Skip to content

Instantly share code, notes, and snippets.

@rjcorwin
Created January 28, 2019 18:16
Show Gist options
  • Save rjcorwin/9eeef2c5a8eea0995c3c0deda384e25f to your computer and use it in GitHub Desktop.
Save rjcorwin/9eeef2c5a8eea0995c3c0deda384e25f to your computer and use it in GitHub Desktop.
A function for filling up storage using PouchDB
var fillUp = async (numberOfDocs, templateDoc, destroy = true) => {
let initialEstimate = await navigator.storage.estimate()
let dbName = `test-${new Date().getTime()}`
let db = new PouchDB(dbName)
delete templateDoc._rev
let i = 0
while (numberOfDocs > i) {
let doc = Object.assign({}, templateDoc, { _id: `${i}` })
await db.put(doc)
i++
}
let concludingEstimate = await navigator.storage.estimate()
console.log(`
Initial Estimate: ${JSON.stringify(initialEstimate)}
Concluding estimate: ${JSON.stringify(concludingEstimate)}
Usage Difference: ${concludingEstimate.usage - initialEstimate.usage} bytes
Average Doc Size: ${(concludingEstimate.usage - initialEstimate.usage) / numberOfDocs} bytes
`)
if (destroy) await db.destroy()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment