Skip to content

Commit 7836c87

Browse files
committed
fix: id 중복 감지 못 해서 update가 아닌 insert 발생하는 이슈 해결
1 parent 926ab4d commit 7836c87

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

apps/backend/src/page/page.repository.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ export class PageRepository extends Repository<Page> {
2323
async bulkUpdate(pages) {
2424
await this.createQueryBuilder()
2525
.insert()
26-
.into(Page)
26+
.into(Page, ['id', 'title', 'content', 'version'])
2727
.values(pages)
28-
.orUpdate(['title', 'content'], ['id'])
28+
.orUpdate(['title', 'content', 'version'], ['id'])
2929
.execute();
3030
}
3131
}

apps/backend/src/tasks/tasks.service.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class TasksService {
1212
private readonly pageService: PageService,
1313
) {}
1414

15-
@Cron(CronExpression.EVERY_SECOND)
15+
@Cron(CronExpression.EVERY_30_SECONDS)
1616
async handleCron() {
1717
console.log(await this.redisService.getAllKeys());
1818
const keys = await this.redisService.getAllKeys();
@@ -22,22 +22,18 @@ export class TasksService {
2222
const { title, content } = await this.redisService.get(key);
2323
const jsonContent = JSON.parse(content);
2424
pages.push({
25-
id: key,
25+
id: parseInt(key),
2626
title,
2727
content: jsonContent,
2828
version: 1,
2929
});
30-
this.pageService.updatePage(parseInt(key), {
31-
title,
32-
content: jsonContent,
33-
});
34-
this.logger.log('데이터베이스 갱신');
35-
}
36-
try {
37-
this.pageService.updateBulkPage(pages);
38-
} catch (exception) {
39-
if (exception instanceof PageNotFoundException) {
40-
}
30+
// this.pageService.updatePage(parseInt(key), {
31+
// title,
32+
// content: jsonContent,
33+
// });
34+
// this.logger.log('데이터베이스 갱신');
4135
}
36+
console.log(pages);
37+
this.pageService.updateBulkPage(pages);
4238
}
4339
}

0 commit comments

Comments
 (0)