Skip to content

Commit

Permalink
WIP: feat: Compact local db on start
Browse files Browse the repository at this point in the history
  Avoid ever growing local database.
  • Loading branch information
taratatach committed Dec 16, 2024
1 parent 0af657e commit 397a893
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ class App {

await this.pouch.addAllViews()
await runMigrations(migrations, this)
await this.pouch.compact()

if (wasUpdated && this.remote) {
try {
Expand Down
10 changes: 10 additions & 0 deletions core/pouch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down

0 comments on commit 397a893

Please sign in to comment.