pouchdb-community / pouchdb-load

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

Incomplete download #66

Closed viinxent closed 5 years ago

viinxent commented 5 years ago

Hey guys,

I have a test dump data which is around ~300mb currently hosted in s3, and I have a proxy server created in express to handle file requests, in my request it seems like its only downloading/loading 28mb worth of data. But if i try to download it normally via axios/curl it seems to be alright.

Here is my code line using pouch load;

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

  const loadDump = dump.dump;
  const loadDumpStatus = `_local/initial_dump_load_status_${loadDump}`;

  try {
    await targetDb.get(loadDumpStatus);
    console.log('@startPouchDumpDownload: Dump file has already been loaded', loadDump);
    return true;
  } catch (err) {
    console.error(
      '@startPouchDumpDownload: Error - getting load dump status - 404 is normal \n',
      'as its trying to check if it already downloaded the dump file \n',
      err,
    );
    if (err.status !== 404) return false;
  }

  try {
    const loadOpts = {
      // ...opts,
      proxy: sourceDb.name,
      ajax: {
        timeout: 999999,
        headers: { Authorization: dump.token },
        withCredentials: false,
      },
    };

    console.log('@startPouchDumpDownload: Loading initial dump file', loadDump);
    await targetDb.load(loadDump, loadOpts);
    await targetDb.put({ _id: loadDumpStatus });
    console.log('@startPouchDumpDownload: Loading initial dump file [done]', loadDump);
    return true;
  } catch (err) {
    console.error(
      '@startPouchDumpDownload: Error downloading dump \n',
      'handing off download to couch replication',
      err.message,
    );
    return false;
  }
}

Thanks in advance