fix deleted labels and highlights are still searchable

This commit is contained in:
Hongbo Wu 2024-02-21 15:06:04 +08:00
parent 51c1d33a09
commit 8f39985f0f
2 changed files with 21 additions and 11 deletions

View file

@ -198,4 +198,10 @@ export class LibraryItem {
@Column('text')
folder!: string
@Column('text')
labelNames?: string[]
@Column('text')
highlightAnnotations?: string[]
}

View file

@ -873,17 +873,6 @@ export const createOrUpdateLibraryItem = async (
if (existingLibraryItem) {
const id = existingLibraryItem.id
// update existing library item
const newItem = await repo.save({
...libraryItem,
id,
slug: existingLibraryItem.slug, // keep the original slug
})
// delete the new item if it's different from the existing one
if (libraryItem.id && libraryItem.id !== id) {
await repo.delete(libraryItem.id)
}
try {
// delete labels and highlights if the item was deleted
@ -898,12 +887,27 @@ export const createOrUpdateLibraryItem = async (
await tx.getRepository(EntityLabel).delete({
libraryItemId: existingLibraryItem.id,
})
libraryItem.labelNames = []
libraryItem.highlightAnnotations = []
}
} catch (error) {
// continue to save the item even if we failed to delete labels and highlights
logger.error('Failed to delete labels and highlights', error)
}
// update existing library item
const newItem = await repo.save({
...libraryItem,
id,
slug: existingLibraryItem.slug, // keep the original slug
})
// delete the new item if it's different from the existing one
if (libraryItem.id && libraryItem.id !== id) {
await repo.delete(libraryItem.id)
}
return newItem
}