sync charts one-at-a-time to reduce database contention and timeouts

This commit is contained in:
Hazelnoot 2024-12-17 10:37:29 -05:00
parent e2352839e4
commit 0b40f2734e
4 changed files with 32 additions and 38 deletions

View file

@ -63,9 +63,9 @@ export class ChartManagementService implements OnApplicationShutdown {
@bindThis
public async start() {
// 20分おきにメモリ情報をDBに書き込み
this.saveIntervalId = setInterval(() => {
this.saveIntervalId = setInterval(async () => {
for (const chart of this.charts) {
chart.save();
await chart.save();
}
this.logger.info('All charts saved');
}, 1000 * 60 * 20);
@ -75,9 +75,9 @@ export class ChartManagementService implements OnApplicationShutdown {
public async dispose(): Promise<void> {
clearInterval(this.saveIntervalId);
if (process.env.NODE_ENV !== 'test') {
await Promise.all(
this.charts.map(chart => chart.save()),
);
for (const chart of this.charts) {
await chart.save();
}
this.logger.info('All charts saved');
}
}