From 38f6fb5a7f70dc2395104c409b089cfbf89f51fe Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Wed, 1 Apr 2026 16:26:16 +0300 Subject: [PATCH] refactor(ocr): rename `ocr_last_processed` to `textExtractionLastProcessed` --- apps/server/src/assets/db/schema.sql | 2 +- apps/server/src/migrations/migrations.ts | 6 +++--- apps/server/src/routes/api/ocr.ts | 6 +++--- apps/server/src/services/ocr/ocr_service.ts | 24 ++++++++++----------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/apps/server/src/assets/db/schema.sql b/apps/server/src/assets/db/schema.sql index e513dd123f..106353e159 100644 --- a/apps/server/src/assets/db/schema.sql +++ b/apps/server/src/assets/db/schema.sql @@ -108,7 +108,7 @@ CREATE TABLE IF NOT EXISTS "blobs" ( `blobId` TEXT NOT NULL, `content` TEXT NULL DEFAULT NULL, `textRepresentation` TEXT DEFAULT NULL, - `ocr_last_processed` TEXT DEFAULT NULL, + `textExtractionLastProcessed` TEXT DEFAULT NULL, `dateModified` TEXT NOT NULL, `utcDateModified` TEXT NOT NULL, PRIMARY KEY(`blobId`) diff --git a/apps/server/src/migrations/migrations.ts b/apps/server/src/migrations/migrations.ts index 70f99d584c..a938395384 100644 --- a/apps/server/src/migrations/migrations.ts +++ b/apps/server/src/migrations/migrations.ts @@ -14,15 +14,15 @@ const MIGRATIONS: (SqlMigration | JsMigration)[] = [ ALTER TABLE blobs ADD COLUMN textRepresentation TEXT DEFAULT NULL; -- Add OCR last processed timestamp to blobs table - ALTER TABLE blobs ADD COLUMN ocr_last_processed TEXT DEFAULT NULL; + ALTER TABLE blobs ADD COLUMN textExtractionLastProcessed TEXT DEFAULT NULL; -- Create index for text representation searches CREATE INDEX IF NOT EXISTS idx_blobs_textRepresentation ON blobs (textRepresentation); -- Create index for OCR last processed timestamp - CREATE INDEX IF NOT EXISTS idx_blobs_ocr_last_processed - ON blobs (ocr_last_processed); + CREATE INDEX IF NOT EXISTS idx_blobs_textExtractionLastProcessed + ON blobs (textExtractionLastProcessed); ` }, // Add missing database indices for query performance diff --git a/apps/server/src/routes/api/ocr.ts b/apps/server/src/routes/api/ocr.ts index 6a32be8615..25edb81814 100644 --- a/apps/server/src/routes/api/ocr.ts +++ b/apps/server/src/routes/api/ocr.ts @@ -570,16 +570,16 @@ async function getNoteOCRText(req: Request, res: Response) { if (note.blobId) { const result = sql.getRow<{ textRepresentation: string | null; - ocr_last_processed: string | null; + textExtractionLastProcessed: string | null; }>(` - SELECT textRepresentation, ocr_last_processed + SELECT textRepresentation, textExtractionLastProcessed FROM blobs WHERE blobId = ? `, [note.blobId]); if (result) { ocrText = result.textRepresentation; - extractedAt = result.ocr_last_processed; + extractedAt = result.textExtractionLastProcessed; } } diff --git a/apps/server/src/services/ocr/ocr_service.ts b/apps/server/src/services/ocr/ocr_service.ts index e1f0c96e06..47d1b88140 100644 --- a/apps/server/src/services/ocr/ocr_service.ts +++ b/apps/server/src/services/ocr/ocr_service.ts @@ -27,7 +27,7 @@ export interface OCRProcessingOptions { interface OCRBlobRow { blobId: string; textRepresentation: string; - ocr_last_processed?: string; + textExtractionLastProcessed?: string; } /** @@ -236,7 +236,7 @@ class OCRService { sql.execute(` UPDATE blobs SET textRepresentation = ?, - ocr_last_processed = ? + textExtractionLastProcessed = ? WHERE blobId = ? `, [ ocrResult.text, @@ -563,9 +563,9 @@ class OCRService { try { const blobInfo = sql.getRow<{ utcDateModified: string; - ocr_last_processed: string | null; + textExtractionLastProcessed: string | null; }>(` - SELECT utcDateModified, ocr_last_processed + SELECT utcDateModified, textExtractionLastProcessed FROM blobs WHERE blobId = ? `, [blobId]); @@ -575,13 +575,13 @@ class OCRService { } // If OCR was never processed, it needs processing - if (!blobInfo.ocr_last_processed) { + if (!blobInfo.textExtractionLastProcessed) { return true; } // If blob was modified after last OCR processing, it needs re-processing const blobModified = new Date(blobInfo.utcDateModified); - const lastOcrProcessed = new Date(blobInfo.ocr_last_processed); + const lastOcrProcessed = new Date(blobInfo.textExtractionLastProcessed); return blobModified > lastOcrProcessed; } catch (error) { @@ -591,7 +591,7 @@ class OCRService { } /** - * Invalidate OCR results for a blob (clear textRepresentation and ocr_last_processed) + * Invalidate OCR results for a blob (clear textRepresentation and textExtractionLastProcessed) */ invalidateOCRResult(blobId: string): void { if (!blobId) { @@ -602,7 +602,7 @@ class OCRService { sql.execute(` UPDATE blobs SET textRepresentation = NULL, - ocr_last_processed = NULL + textExtractionLastProcessed = NULL WHERE blobId = ? `, [blobId]); @@ -653,8 +653,8 @@ class OCRService { AND n.isDeleted = 0 AND n.blobId IS NOT NULL AND ( - b.ocr_last_processed IS NULL - OR b.utcDateModified > b.ocr_last_processed + b.textExtractionLastProcessed IS NULL + OR b.utcDateModified > b.textExtractionLastProcessed ) `); @@ -693,8 +693,8 @@ class OCRService { AND a.isDeleted = 0 AND a.blobId IS NOT NULL AND ( - b.ocr_last_processed IS NULL - OR b.utcDateModified > b.ocr_last_processed + b.textExtractionLastProcessed IS NULL + OR b.utcDateModified > b.textExtractionLastProcessed ) `);