fix(meilisearch): 전체 동기화 시 DB에 없는 문서 삭제
- syncAllSchedules()에서 Meilisearch의 모든 문서 ID 조회 - DB에 없는 문서는 Meilisearch에서 삭제 - 삭제된 일정이 검색에 계속 나타나는 문제 해결 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
294018c93b
commit
c86cda00ae
1 changed files with 21 additions and 1 deletions
|
|
@ -271,7 +271,7 @@ export async function deleteSchedule(meilisearch, scheduleId) {
|
|||
}
|
||||
|
||||
/**
|
||||
* 전체 일정 동기화
|
||||
* 전체 일정 동기화 (DB에 없는 문서는 삭제)
|
||||
*/
|
||||
export async function syncAllSchedules(meilisearch, db) {
|
||||
try {
|
||||
|
|
@ -303,6 +303,26 @@ export async function syncAllSchedules(meilisearch, db) {
|
|||
`);
|
||||
|
||||
const index = meilisearch.index(INDEX_NAME);
|
||||
const dbIds = new Set(schedules.map(s => s.id));
|
||||
|
||||
// Meilisearch에서 모든 문서 ID 조회
|
||||
let meiliIds = [];
|
||||
let offset = 0;
|
||||
const limit = 1000;
|
||||
while (true) {
|
||||
const docs = await index.getDocuments({ offset, limit, fields: ['id'] });
|
||||
if (docs.results.length === 0) break;
|
||||
meiliIds.push(...docs.results.map(d => d.id));
|
||||
if (docs.results.length < limit) break;
|
||||
offset += limit;
|
||||
}
|
||||
|
||||
// DB에 없는 문서 삭제
|
||||
const idsToDelete = meiliIds.filter(id => !dbIds.has(id));
|
||||
if (idsToDelete.length > 0) {
|
||||
await index.deleteDocuments(idsToDelete);
|
||||
logger.info(`${idsToDelete.length}개 문서 삭제`);
|
||||
}
|
||||
|
||||
// 문서 변환 (addDocuments는 같은 ID면 자동 업데이트)
|
||||
const documents = schedules.map(s => ({
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue