pouchdb-community / pouchdb-load

Load documents into CouchDB/PouchDB from a dumpfile
Apache License 2.0
120 stars 33 forks source link

More of a question than a bug, regarding the proxy and not re-downloading the file #65

Closed viinxent closed 5 years ago

viinxent commented 5 years ago

In the docs this was mention:

This will tell the plugin that the dumpfile 'http://example.com/my-dump-file.txt' is just a proxy for 'http://mysite.com/mydb'. So when you pick up replication again, it won't start from 0 but rather will start from the last checkpoint reported by the dump file

But when I call "db.load" it seems that it downloads the file again as I can see it on my network tab. I only want it to download once if its already up-to-date with the sequence then don't re-download. If this is how it works then I could proceed to my backup plan to just use a flag. Else am I missing something?

Here is my sample code -

export function startPouchDumpDownload(sourceDb, targetDb, opts, dump) {
  if (!(dump || {}).dump) return false;

  const loadDump = dump.dump;
  const loadOpts = {
    ...opts, // filters, other opts for pouchdb, thinking the 'since' would work guess not 
    proxy: sourceDb.name, // Just a dbname nothing special
    ajax: { headers: { Authorization: dump.token } },
  };

  targetDb.load(loadDump, loadOpts).catch((err) => {
    console.error('@startPouchDumpDownload: Error', err);
    throw err;
  });

  console.error(`[${targetDb.name}] Source: ${sourceDb.name} | Dump: ${dump.dump}`);
  return true;
}
viinxent commented 5 years ago

Never mind found what I was looking for. Didn't read enough through the documentation.

Notes on idempotency The load() operation is idempotent, meaning that you can run it over and over again, and it won't create duplicate documents in the target database. However, it's inefficient to run the load() every time the user starts your app. So if you'd like, you can use "local documents" to remember whether or not this database has already been loaded: