Created
March 18, 2021 02:58
-
-
Save chrisekelley/8041e9ede5453f5b91d2b207ca68e716 to your computer and use it in GitHub Desktop.
Testing Pouch/sqlite memory
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
| // Open the app, open js debugger and ADB console | |
| // Change the size, in MB | |
| // After running this test, close the app to clear memory. | |
| // If the test is successull it will return the payload size in MB | |
| // and on the next line it will display the doc: | |
| // 15 MB | |
| // newDoc: {"ok":true,"id":"26670b3f-7b36-43d4-a5cb-1783b0108c77","rev":"1-c0f943597a9c1f9160d0880081e91803"} | |
| // When it fails, it only returns the payload size. | |
| // Get the error from ADB console. | |
| let size = 15 | |
| let pouchDBOptions = { | |
| adapter: 'cordova-sqlite', | |
| location: 'default', | |
| androidDatabaseImplementation: 2, | |
| key:'test' | |
| } | |
| let pouch = new PouchDB('test', pouchDBOptions); | |
| function formatBytes(a,b=2){if(0===a)return"0 Bytes";const c=0>b?0:b,d=Math.floor(Math.log(a)/Math.log(1024));return parseFloat((a/Math.pow(1024,d)).toFixed(c))+" "+["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"][d]} | |
| let s = 'x'.repeat(size*1024*1024) | |
| let len =(new TextEncoder().encode(s)).length | |
| console.log(formatBytes(len)) | |
| let doc = { | |
| foo:s | |
| } | |
| try { | |
| let newDoc = await pouch.post(doc) | |
| console.log("newDoc: " + JSON.stringify(newDoc)) | |
| } catch (e) { | |
| console.log("Database error: " + e); | |
| console.trace(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment