Skip to content

Build your personal knowledge base with Trilium Notes

client/cleanup tool: add a backend log message to indicate the DB vacuuming operation start

Adorian Doran3024f48ce70c
diff --git a/apps/server/src/routes/api/database.spec.ts b/apps/server/src/routes/api/database.spec.ts
index 3ffc9fa3fd..530213d96e 100644
--- a/apps/server/src/routes/api/database.spec.ts
+++ b/apps/server/src/routes/api/database.spec.ts
@@ -41,9 +41,14 @@ describe("Database API", () => {
expect(sizeAfter).toBeGreaterThan(0);
expect(sizeAfter).toBeLessThanOrEqual(sizeBefore);
+ // Announced on the way in as well as on the way out: a rebuild the process is killed partway
+ // through leaves only the first line behind, and that is the point of it.
+ expect(logged.mock.calls[0][0]).toBe(
+ `Compacting the database (${utils.formatSize(sizeBefore)}). This may take several minutes.`);
+
// Recorded in the sizes a reader thinks in, not in bytes, and answering for how long it
// held the database.
- expect(logged).toHaveBeenCalledWith(
+ expect(logged).toHaveBeenLastCalledWith(
expect.stringMatching(new RegExp(
`^Compacted the database from ${utils.formatSize(sizeBefore)}`
+ ` to ${utils.formatSize(sizeAfter)} in \\d+ ms\\.$`)));
diff --git a/apps/server/src/routes/api/database.ts b/apps/server/src/routes/api/database.ts
index 20402e91d1..b57ed0bb2c 100644
--- a/apps/server/src/routes/api/database.ts
+++ b/apps/server/src/routes/api/database.ts
@@ -30,6 +30,12 @@ function vacuumDatabase() {
// answering for is how long the whole thing held the database.
const startedAt = Date.now();
const sizeBefore = databaseBytes();
+
+ // Announced before the rebuild starts, not only once it ends: this holds the process for minutes
+ // on a large database, and if it is killed or the machine goes down in the meantime, this line
+ // is the only record that one was ever under way.
+ getLog().info(`Compacting the database (${utils.formatSize(sizeBefore)}). This may take several minutes.`);
+
sql.execute("VACUUM");
const sizeAfter = databaseBytes();