Skip to content

Commit

Permalink
Fix projects getting deleted from meili index
Browse files Browse the repository at this point in the history
  • Loading branch information
kasbah committed Sep 26, 2024
1 parent 873bf5b commit 5e4c296
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions processor/src/tasks/addToSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 5e4c296

Please sign in to comment.