chore: move visibility updates to transaction

This commit is contained in:
bwees 2025-12-23 12:02:52 -05:00
parent d28cefba86
commit ba311ccae9
No known key found for this signature in database
2 changed files with 52 additions and 47 deletions

View File

@ -78,31 +78,34 @@ export class OcrRepository {
visible: AssetOcrResponseDto[],
hidden: AssetOcrResponseDto[],
): Promise<void> {
if (visible.length > 0) {
await this.db
.updateTable('asset_ocr')
.set({ isVisible: true })
.where(
'asset_ocr.id',
'in',
visible.map((i) => i.id),
)
.execute();
}
if (hidden.length > 0) {
await this.db
.updateTable('asset_ocr')
.set({ isVisible: false })
.where(
'asset_ocr.id',
'in',
hidden.map((i) => i.id),
)
.execute();
}
const searchText = visible.map((item) => item.text.trim()).join(' ');
await this.db.updateTable('ocr_search').set({ text: searchText }).where('assetId', '=', assetId).execute();
await this.db.transaction().execute(async (trx) => {
if (visible.length > 0) {
await trx
.updateTable('asset_ocr')
.set({ isVisible: true })
.where(
'asset_ocr.id',
'in',
visible.map((i) => i.id),
)
.execute();
}
if (hidden.length > 0) {
await trx
.updateTable('asset_ocr')
.set({ isVisible: false })
.where(
'asset_ocr.id',
'in',
hidden.map((i) => i.id),
)
.execute();
}
await trx.updateTable('ocr_search').set({ text: searchText }).where('assetId', '=', assetId).execute();
});
}
}

View File

@ -554,28 +554,30 @@ export class PersonRepository {
return;
}
if (visible.length > 0) {
await this.db
.updateTable('asset_face')
.set({ isVisible: true })
.where(
'asset_face.id',
'in',
visible.map(({ id }) => id),
)
.execute();
}
await this.db.transaction().execute(async (trx) => {
if (visible.length > 0) {
await trx
.updateTable('asset_face')
.set({ isVisible: true })
.where(
'asset_face.id',
'in',
visible.map(({ id }) => id),
)
.execute();
}
if (hidden.length > 0) {
await this.db
.updateTable('asset_face')
.set({ isVisible: false })
.where(
'asset_face.id',
'in',
hidden.map(({ id }) => id),
)
.execute();
}
if (hidden.length > 0) {
await trx
.updateTable('asset_face')
.set({ isVisible: false })
.where(
'asset_face.id',
'in',
hidden.map(({ id }) => id),
)
.execute();
}
});
}
}