Browse Source

Improve snapshot caching

pull/3393/head
Thomas Kaul 1 year ago
parent
commit
9e7c725059
  1. 14
      apps/api/src/app/portfolio/portfolio.service.ts
  2. 6
      apps/api/src/app/user/user.controller.ts
  3. 17
      apps/api/src/app/user/user.service.ts
  4. 2
      apps/client/src/app/components/account-detail-dialog/account-detail-dialog.html
  5. 6
      libs/common/src/lib/helper.ts

14
apps/api/src/app/portfolio/portfolio.service.ts

@ -1153,7 +1153,19 @@ export class PortfolioService {
netWorth,
totalInvestment,
valueWithCurrencyEffect
} = last(chart);
} =
chart?.length > 0
? last(chart)
: {
grossPerformancePercent: 0,
netPerformance: 0,
netPerformanceInPercentage: 0,
netPerformanceInPercentageWithCurrencyEffect: 0,
netPerformanceWithCurrencyEffect: 0,
netWorth: 0,
totalInvestment: 0,
valueWithCurrencyEffect: 0
};
return {
chart,

6
apps/api/src/app/user/user.controller.ts

@ -144,6 +144,11 @@ export class UserController {
);
}
const haveFiltersChanged =
'filters.accounts' in data ||
'filters.assetClasses' in data ||
'filters.tags' in data;
const userSettings: UserSettings = {
...(<UserSettings>this.request.user.Settings.settings),
...data
@ -157,6 +162,7 @@ export class UserController {
return this.userService.updateUserSetting({
userSettings,
emitPortfolioChangedEvent: haveFiltersChanged,
userId: this.request.user.id
});
}

17
apps/api/src/app/user/user.service.ts

@ -421,9 +421,11 @@ export class UserService {
}
public async updateUserSetting({
emitPortfolioChangedEvent,
userId,
userSettings
}: {
emitPortfolioChangedEvent: boolean;
userId: string;
userSettings: UserSettings;
}) {
@ -444,13 +446,14 @@ export class UserService {
}
});
// TODO: Handle changes in filters?
// this.eventEmitter.emit(
// PortfolioChangedEvent.getName(),
// new PortfolioChangedEvent({
// userId
// })
// );
if (emitPortfolioChangedEvent) {
this.eventEmitter.emit(
PortfolioChangedEvent.getName(),
new PortfolioChangedEvent({
userId
})
);
}
return settings;
}

2
apps/client/src/app/components/account-detail-dialog/account-detail-dialog.html

@ -20,6 +20,7 @@
</div>
</div>
<!-- TODO
<div class="chart-container mb-3">
<gf-investment-chart
class="h-100"
@ -32,6 +33,7 @@
[locale]="user?.settings?.locale"
/>
</div>
-->
<div class="mb-3 row">
<div class="col-6 mb-3">

6
libs/common/src/lib/helper.ts

@ -350,7 +350,11 @@ export function isDerivedCurrency(aCurrency: string) {
});
}
export function parseDate(date: string): Date | null {
export function parseDate(date: string): Date {
if (!date) {
return undefined;
}
// Transform 'yyyyMMdd' format to supported format by parse function
if (date?.length === 8) {
const match = date.match(/^(\d{4})(\d{2})(\d{2})$/);

Loading…
Cancel
Save