Skip to content

Build your personal knowledge base with Trilium Notes

chore(ocr): address requested changes

Elian Doran70bc707e3a6c
diff --git a/apps/client/src/services/content_renderer.ts b/apps/client/src/services/content_renderer.ts
index 0b29513c2f..e037383a73 100644
--- a/apps/client/src/services/content_renderer.ts
+++ b/apps/client/src/services/content_renderer.ts
@@ -148,7 +148,7 @@ async function renderImage(entity: FNote | FAttachment, $renderedContent: JQuery
if (entity instanceof FNote) {
url = `api/images/${entity.noteId}/${encodedTitle}?${Math.random()}`;
} else if (entity instanceof FAttachment) {
- url = `api/attachments/${entity.attachmentId}/image/${encodedTitle}?${entity.utcDateModified}">`;
+ url = `api/attachments/${entity.attachmentId}/image/${encodedTitle}?${entity.utcDateModified}`;
}
$renderedContent // styles needed for the zoom to work well
diff --git a/apps/server/src/services/search/services/search.ts b/apps/server/src/services/search/services/search.ts
index fd4d8dea1b..09b003a2e3 100644
--- a/apps/server/src/services/search/services/search.ts
+++ b/apps/server/src/services/search/services/search.ts
@@ -440,24 +440,19 @@ function findFirstNoteWithQuery(query: string, searchContext: SearchContext): BN
* or any of its attachment blobs.
*/
function getTextRepresentationForNote(note: BNote): string | null {
- const noteBlob = becca.getBlob({ blobId: note.blobId });
- if (noteBlob?.textRepresentation) {
- return noteBlob.textRepresentation;
- }
-
- const attachmentBlobIds = sql.getColumn<string>(
- `SELECT blobId FROM attachments WHERE ownerId = ? AND isDeleted = 0`,
- [note.noteId]
- );
-
- for (const blobId of attachmentBlobIds) {
- const blob = becca.getBlob({ blobId });
- if (blob?.textRepresentation) {
- return blob.textRepresentation;
- }
- }
-
- return null;
+ // Query only textRepresentation to avoid loading large binary content into memory.
+ const row = sql.getRow<{ textRepresentation: string | null }>(`
+ SELECT b.textRepresentation FROM blobs b
+ WHERE b.textRepresentation IS NOT NULL
+ AND b.textRepresentation != ''
+ AND (
+ b.blobId = ?
+ OR b.blobId IN (SELECT blobId FROM attachments WHERE ownerId = ? AND isDeleted = 0)
+ )
+ LIMIT 1
+ `, [note.blobId, note.noteId]);
+
+ return row?.textRepresentation ?? null;
}
function extractContentSnippet(noteId: string, searchTokens: string[], maxLength: number = 200): string {