diff --git a/src/db/repository.ts b/src/db/repository.ts index fb306ae..f627909 100644 --- a/src/db/repository.ts +++ b/src/db/repository.ts @@ -47,6 +47,22 @@ export class Repository { } } + async getEntityById(id: string): Promise { + try { + const results = await this.db.exec({ + sql: `SELECT * FROM entities WHERE id = ?`, + bind: [id], + returnValue: 'resultRows', + rowMode: 'object', + }) as Record[]; + if (results.length === 0) return null; + return this.parseMetadata(results[0]); + } catch (err) { + logger.error('Failed to fetch entity by id', err); + throw new AppError('Failed to fetch entity by id', 'DB_ERROR', err); + } + } + async getEntityByName(name: string): Promise { try { const results = await this.db.exec({ diff --git a/src/lib/search.ts b/src/lib/search.ts index a67469f..c82ad4a 100644 --- a/src/lib/search.ts +++ b/src/lib/search.ts @@ -131,8 +131,7 @@ export const upsertToSearchIndex = async (entityId: string) => { try { await removeFromSearchIndex(entityId); - const entities = await repository.getAllEntities(); - const entity = entities.find(e => e.id === entityId); + const entity = await repository.getEntityById(entityId); if (entity) { const claims = await repository.getClaimsByEntityId(entity.id!);