From 397a893b3ca116ef1f72708f05b9c37232510c22 Mon Sep 17 00:00:00 2001 From: Erwan Guyader Date: Mon, 16 Dec 2024 11:10:23 +0100 Subject: [PATCH] WIP: feat: Compact local db on start Avoid ever growing local database. --- core/app.js | 1 + core/pouch/index.js | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/core/app.js b/core/app.js index 76ddc8e02..20f76d003 100644 --- a/core/app.js +++ b/core/app.js @@ -416,6 +416,7 @@ class App { await this.pouch.addAllViews() await runMigrations(migrations, this) + await this.pouch.compact() if (wasUpdated && this.remote) { try { diff --git a/core/pouch/index.js b/core/pouch/index.js index a695b4678..6a0dc52c2 100644 --- a/core/pouch/index.js +++ b/core/pouch/index.js @@ -98,6 +98,16 @@ class Pouch { }) } + async compact() { + log.info('compacting db...') + + try { + await this.db.compact() + } catch (err) { + log.error('failed to compact db', { err, sentry: true }) + } + } + /* Mini ODM */ /* Catch uncaught exceptions raised by PouchDB when calling `allDocs`.