Browse Source

optimize database query execution for portfolio chart

pull/239/head
Valentin Zickner 3 years ago
committed by Thomas
parent
commit
ddf24163b4
  1. 19
      apps/api/src/app/core/portfolio-calculator.ts

19
apps/api/src/app/core/portfolio-calculator.ts

@ -142,7 +142,7 @@ export class PortfolioCalculator {
const start = dparse(startDate);
const end = dparse(endDate);
const timelinePeriod: TimelinePeriod[] = [];
const timelinePeriodPromises: Promise<TimelinePeriod>[] = [];
let i = 0;
let j = -1;
for (
@ -162,7 +162,17 @@ export class PortfolioCalculator {
) {
j++;
}
timelinePeriodPromises.push(this.getTimePeriodForDate(j, currentDate));
}
const timelinePeriod: TimelinePeriod[] = await Promise.all(
timelinePeriodPromises
);
return timelinePeriod;
}
private async getTimePeriodForDate(j: number, currentDate: Date) {
let investment: Big = new Big(0);
const promises = [];
if (j >= 0) {
@ -185,15 +195,12 @@ export class PortfolioCalculator {
(a, b) => a.add(b),
new Big(0)
);
timelinePeriod.push({
return {
date: format(currentDate, DATE_FORMAT),
grossPerformance: value.minus(investment),
investment,
value
});
}
return timelinePeriod;
};
}
private getFactor(type: OrderType) {

Loading…
Cancel
Save