optimize database query execution for portfolio chart

pull/239/head
Valentin Zickner 3 years ago committed by Thomas
parent b26521c4bd
commit ddf24163b4

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

Loading…
Cancel
Save