optimize database query execution for portfolio chart
This commit is contained in:
parent
b26521c4bd
commit
ddf24163b4
@ -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…
x
Reference in New Issue
Block a user