Created
January 28, 2019 18:16
-
-
Save rjcorwin/9eeef2c5a8eea0995c3c0deda384e25f to your computer and use it in GitHub Desktop.
A function for filling up storage using PouchDB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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