|
|
@ -3,10 +3,12 @@ import { PortfolioSnapshotService } from '@ghostfolio/api/services/queues/portfo |
|
|
import { RedisCacheService } from '@ghostfolio/api/services/redis-cache/redis-cache.service'; |
|
|
import { RedisCacheService } from '@ghostfolio/api/services/redis-cache/redis-cache.service'; |
|
|
import { UserService } from '@ghostfolio/api/services/user/user.service'; |
|
|
import { UserService } from '@ghostfolio/api/services/user/user.service'; |
|
|
import { |
|
|
import { |
|
|
|
|
|
DEFAULT_CURRENCY, |
|
|
PORTFOLIO_SNAPSHOT_COMPUTATION_QUEUE_PRIORITY_LOW, |
|
|
PORTFOLIO_SNAPSHOT_COMPUTATION_QUEUE_PRIORITY_LOW, |
|
|
PORTFOLIO_SNAPSHOT_PROCESS_JOB_NAME, |
|
|
PORTFOLIO_SNAPSHOT_PROCESS_JOB_NAME, |
|
|
PORTFOLIO_SNAPSHOT_PROCESS_JOB_OPTIONS |
|
|
PORTFOLIO_SNAPSHOT_PROCESS_JOB_OPTIONS |
|
|
} from '@ghostfolio/common/config'; |
|
|
} from '@ghostfolio/common/config'; |
|
|
|
|
|
import { PerformanceCalculationType } from '@ghostfolio/common/types/performance-calculation-type.type'; |
|
|
|
|
|
|
|
|
import { Injectable, Logger } from '@nestjs/common'; |
|
|
import { Injectable, Logger } from '@nestjs/common'; |
|
|
import { OnEvent } from '@nestjs/event-emitter'; |
|
|
import { OnEvent } from '@nestjs/event-emitter'; |
|
|
@ -67,21 +69,25 @@ export class PortfolioChangedListener { |
|
|
userSettings |
|
|
userSettings |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const calculationType = |
|
|
|
|
|
userSettings.performanceCalculationType ?? |
|
|
|
|
|
PerformanceCalculationType.ROAI; |
|
|
|
|
|
|
|
|
// Recompute in the background to avoid a cold start on the next request
|
|
|
// Recompute in the background to avoid a cold start on the next request
|
|
|
await this.portfolioSnapshotService.addJobToQueue({ |
|
|
await this.portfolioSnapshotService.addJobToQueue({ |
|
|
data: { |
|
|
data: { |
|
|
|
|
|
calculationType, |
|
|
filters, |
|
|
filters, |
|
|
userId, |
|
|
userId, |
|
|
calculationType: userSettings.performanceCalculationType, |
|
|
userCurrency: userSettings.baseCurrency ?? DEFAULT_CURRENCY |
|
|
userCurrency: userSettings.baseCurrency |
|
|
|
|
|
}, |
|
|
}, |
|
|
name: PORTFOLIO_SNAPSHOT_PROCESS_JOB_NAME, |
|
|
name: PORTFOLIO_SNAPSHOT_PROCESS_JOB_NAME, |
|
|
opts: { |
|
|
opts: { |
|
|
...PORTFOLIO_SNAPSHOT_PROCESS_JOB_OPTIONS, |
|
|
...PORTFOLIO_SNAPSHOT_PROCESS_JOB_OPTIONS, |
|
|
jobId: this.redisCacheService.getPortfolioSnapshotKey({ |
|
|
jobId: this.redisCacheService.getPortfolioSnapshotKey({ |
|
|
|
|
|
calculationType, |
|
|
filters, |
|
|
filters, |
|
|
userId, |
|
|
userId |
|
|
calculationType: userSettings.performanceCalculationType |
|
|
|
|
|
}), |
|
|
}), |
|
|
priority: PORTFOLIO_SNAPSHOT_COMPUTATION_QUEUE_PRIORITY_LOW |
|
|
priority: PORTFOLIO_SNAPSHOT_COMPUTATION_QUEUE_PRIORITY_LOW |
|
|
} |
|
|
} |
|
|
|