From 5e4c296eff5294abb9830409bdcc3af8af94a868 Mon Sep 17 00:00:00 2001 From: Kaspar Emanuel Date: Thu, 26 Sep 2024 01:32:46 +0100 Subject: [PATCH] Fix projects getting deleted from meili index --- processor/src/tasks/addToSearch.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/processor/src/tasks/addToSearch.ts b/processor/src/tasks/addToSearch.ts index ffdef5c271..dee0b40ca4 100644 --- a/processor/src/tasks/addToSearch.ts +++ b/processor/src/tasks/addToSearch.ts @@ -55,14 +55,18 @@ export default async function addToSearch( await meiliIndex.addDocuments([document]) - // if there are any lingering docs with an old gitHash then the multi project - // was renamed (so they were not over-written with new gitHash above), so we + // if there are any lingering docs with an old gitHash then it's possible a multi project + // was renamed (and thus document was not over-written with new gitHash above), so we // delete them. - const renamedMultis = await meiliIndex.search('', { - filter: `(repoId = ${giteaId}) AND (gitHash != ${hash})`, + // this has a lot of potential issues, we should handle multi repos as one and get rid of this in the future + const staleMultis = await meiliIndex.search('', { + filter: `(repoId = ${giteaId}) AND (id != ${searchId}) AND (gitHash != ${hash})`, }) - if (renamedMultis.hits.length > 0) { - const docIds = renamedMultis.hits.map(x => x.id) + if (staleMultis.hits.length > 0) { + const docIds = staleMultis.hits.map(x => x.id) + log.debug( + `meilisearch: deleting possibly stale documents: ${docIds.join(', ')}`, + ) await meiliIndex.deleteDocuments(docIds) } }