hoodiehq / hoodie-client

:dog: Client API for the Hoodie server
Apache License 2.0
34 stars 25 forks source link

Compacting PouchDB #147

Closed tommyku closed 7 years ago

tommyku commented 7 years ago

I wanted to compact my PouchDB database because my app starts taking too much storage.

I could write the compaction code myself if hoodie object exposes the internal PouchDB instance but it doesn't. I could also enable auto_compaction on instantiation of PouchDB instance but it is inside get-api which I can't access.

Would it be better to enable auto_compaction by default in get-api, let user pass in PouchDB constructor options to hoodie constructor, or expose the PouchDB instance?

gnowoel commented 7 years ago

Same problem. And here is my workaround:

import Hoodie from '@hoodie/client';
import PouchDB from 'pouchdb-browser';

const myPouch = PouchDB.defaults({
  auto_compaction: true
});

const hoodie = new Hoodie({
  url: window.location.origin,
  PouchDB: myPouch
});

I don't include /hoodie/client.js in my frontend code. Instead, I instantiate Hoodie myself, with PouchDB of custom defaults.

gr2m commented 7 years ago

I could write the compaction code myself if hoodie object exposes the internal PouchDB instance

In fact it does, at hoodie.store.db. Note that the instance is replaced each time a user signs in / signs out, as the database gets destroyed

I don't include /hoodie/client.js in my frontend code. Instead, I instantiate Hoodie myself, with PouchDB of custom defaults.

That is the way to do it for more sophisticated apps 👍

tommyku commented 7 years ago

@gr2m Yeah hoodie.store.db does expose the PouchDB instance with which I can manage the db directly.

@gnowoel Thanks! Your approach is clean and handy especially if I want to keep all configs at one place.