From 8f39985f0fe8b6791ff212a255d9ef51c061872e Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Wed, 21 Feb 2024 15:06:04 +0800 Subject: [PATCH] fix deleted labels and highlights are still searchable --- packages/api/src/entity/library_item.ts | 6 ++++++ packages/api/src/services/library_item.ts | 26 +++++++++++++---------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/packages/api/src/entity/library_item.ts b/packages/api/src/entity/library_item.ts index f5c15d42e..f127f52b5 100644 --- a/packages/api/src/entity/library_item.ts +++ b/packages/api/src/entity/library_item.ts @@ -198,4 +198,10 @@ export class LibraryItem { @Column('text') folder!: string + + @Column('text') + labelNames?: string[] + + @Column('text') + highlightAnnotations?: string[] } diff --git a/packages/api/src/services/library_item.ts b/packages/api/src/services/library_item.ts index 119eabc6f..37422d920 100644 --- a/packages/api/src/services/library_item.ts +++ b/packages/api/src/services/library_item.ts @@ -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 }