Skip to content

Build your personal knowledge base with Trilium Notes

chore(becca): add log for cache memory consumption

Elian Doran6763f4f40396
diff --git a/apps/server/src/becca/becca-interface.ts b/apps/server/src/becca/becca-interface.ts
index 6d5d13d07b..f1e7c7fde3 100644
--- a/apps/server/src/becca/becca-interface.ts
+++ b/apps/server/src/becca/becca-interface.ts
@@ -1,4 +1,6 @@
import sql from "../services/sql.js";
+import log from "../services/log.js";
+import { formatSize } from "../services/utils.js";
import NoteSet from "../services/search/note_set.js";
import NotFoundError from "../errors/not_found_error.js";
import type BOption from "./entities/boption.js";
@@ -277,6 +279,9 @@ export default class Becca {
*/
getFlatTextIndex(): { notes: BNote[], flatTexts: string[], noteIdToIdx: Map<string, number> } {
if (!this.flatTextIndex) {
+ // Measure heap before building
+ const heapBefore = process.memoryUsage().heapUsed;
+
const allNoteSet = this.getAllNoteSet();
const notes: BNote[] = [];
const flatTexts: string[] = [];
@@ -290,6 +295,11 @@ export default class Becca {
this.flatTextIndex = { notes, flatTexts, noteIdToIdx };
this.dirtyFlatTextNoteIds.clear();
+
+ // Measure heap after building and log
+ const heapAfter = process.memoryUsage().heapUsed;
+ const heapDelta = heapAfter - heapBefore;
+ log.info(`Flat text search index built: ${notes.length} notes, ${formatSize(heapDelta)}`);
} else if (this.dirtyFlatTextNoteIds.size > 0) {
// Incremental update: only recompute flat texts for dirtied notes
const { flatTexts, noteIdToIdx } = this.flatTextIndex;