最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to calculate indexedDB table size in chrome? - Stack Overflow

programmeradmin2浏览0评论

I am using pouchDB with IndexedDB adapter on chrome browser and I want to calculate the each IndexedDB database size. I use the code from .js to do the calculation.

What I found is that the total size of the databases is far greater than the webkit temporary storage usage.

Below screenshot is the total storage (255MB) used by my application.

You will see there are 5 databases saved in IndexedDB. And below output is the calculation result for the size of each database. You will see that the total size is about 389MB. I wonder why they are quite different. Which one is the correct one?

--------- _pouch_products -------------
VM1633:51  - attach-seq-store   : 0 B
VM1633:51  - attach-store   : 0 B
VM1633:51  - by-sequence    : 86.7 MB
VM1633:51  - detect-blob-support    : 2 B
VM1633:51  - document-store : 92.3 MB
VM1633:51  - local-store    : 6.1 KB
VM1633:51  - meta-store : 96 B
VM1633:57 TOTAL: 179.0 MB

--------- _pouch_transactions -------------
VM1633:51  - attach-seq-store   : 0 B
VM1633:51  - attach-store   : 0 B
VM1633:51  - by-sequence    : 13.7 KB
VM1633:51  - detect-blob-support    : 2 B
VM1633:51  - document-store : 2.2 KB
VM1633:51  - local-store    : 4.2 KB
VM1633:51  - meta-store : 96 B
VM1633:57 TOTAL: 20.2 KB

--------- _pouch_products-mrview-4c294f20854f412a71c9e7cf2f9cc58f -------------
VM1633:51  - attach-seq-store   : 0 B
VM1633:51  - attach-store   : 0 B
VM1633:51  - by-sequence    : 11.9 MB
VM1633:51  - detect-blob-support    : 0 B
VM1633:51  - document-store : 35.3 MB
VM1633:51  - local-store    : 15.1 MB
VM1633:51  - meta-store : 136 B
VM1633:57 TOTAL: 62.3 MB

--------- _pouch_products-mrview-fdca57d512425c6ed0f20311a4f8d6d1 -------------
VM1633:51  - attach-seq-store   : 0 B
VM1633:51  - attach-store   : 0 B
VM1633:51  - by-sequence    : 86.2 MB
VM1633:51  - detect-blob-support    : 0 B
VM1633:51  - document-store : 44.2 MB
VM1633:51  - local-store    : 17.4 MB
VM1633:51  - meta-store : 136 B
VM1633:57 TOTAL: 147.7 MB
--------- _product_alerts -------------
VM1633:57 TOTAL: 0 B

I am using pouchDB with IndexedDB adapter on chrome browser and I want to calculate the each IndexedDB database size. I use the code from https://github./jonnysmith1981/getIndexedDbSize/blob/master/getIndexedDbSize.js to do the calculation.

What I found is that the total size of the databases is far greater than the webkit temporary storage usage.

Below screenshot is the total storage (255MB) used by my application.

You will see there are 5 databases saved in IndexedDB. And below output is the calculation result for the size of each database. You will see that the total size is about 389MB. I wonder why they are quite different. Which one is the correct one?

--------- _pouch_products -------------
VM1633:51  - attach-seq-store   : 0 B
VM1633:51  - attach-store   : 0 B
VM1633:51  - by-sequence    : 86.7 MB
VM1633:51  - detect-blob-support    : 2 B
VM1633:51  - document-store : 92.3 MB
VM1633:51  - local-store    : 6.1 KB
VM1633:51  - meta-store : 96 B
VM1633:57 TOTAL: 179.0 MB

--------- _pouch_transactions -------------
VM1633:51  - attach-seq-store   : 0 B
VM1633:51  - attach-store   : 0 B
VM1633:51  - by-sequence    : 13.7 KB
VM1633:51  - detect-blob-support    : 2 B
VM1633:51  - document-store : 2.2 KB
VM1633:51  - local-store    : 4.2 KB
VM1633:51  - meta-store : 96 B
VM1633:57 TOTAL: 20.2 KB

--------- _pouch_products-mrview-4c294f20854f412a71c9e7cf2f9cc58f -------------
VM1633:51  - attach-seq-store   : 0 B
VM1633:51  - attach-store   : 0 B
VM1633:51  - by-sequence    : 11.9 MB
VM1633:51  - detect-blob-support    : 0 B
VM1633:51  - document-store : 35.3 MB
VM1633:51  - local-store    : 15.1 MB
VM1633:51  - meta-store : 136 B
VM1633:57 TOTAL: 62.3 MB

--------- _pouch_products-mrview-fdca57d512425c6ed0f20311a4f8d6d1 -------------
VM1633:51  - attach-seq-store   : 0 B
VM1633:51  - attach-store   : 0 B
VM1633:51  - by-sequence    : 86.2 MB
VM1633:51  - detect-blob-support    : 0 B
VM1633:51  - document-store : 44.2 MB
VM1633:51  - local-store    : 17.4 MB
VM1633:51  - meta-store : 136 B
VM1633:57 TOTAL: 147.7 MB
--------- _product_alerts -------------
VM1633:57 TOTAL: 0 B
Share Improve this question asked Apr 2, 2019 at 10:23 Joey Yi ZhaoJoey Yi Zhao 42.8k87 gold badges357 silver badges661 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

The Indexed DB API does not provide a way to query the size of databases (or stores/indexes). Translating keys and values into bytes is also something performed by the browser and is not visible to script. So the script must be doing an approximation, e.g. puting the size of all keys and values in a store when serialized as strings.

The Indexed DB implementation in Chrome uses a backing store called leveldb which has various size optimizations, such as key prefix pression and value pression using another library called "snappy". Strings can also be serialized as bytes in numerous ways (e.g. JS strings are 16-bits per character, which could be naively stored as 2 bytes per character or UTF-8 encoded to 1-4 bytes per character). The backing store also lazily pacts when data is deleted or overwritten, so it may end up taking more space than it needs temporarily.

None of these optimizations are visible to script either, and all will vary cross browsers, so the approximation will be... approximate. Given all of this, an estimate of 389MB vs. the 255MB the browser reports is pretty good!

In Chrome we're experimenting with a per-type breakdown reported via the navigator.storage.estimate() API that would give the exact value for each storage type (e.g. Indexed DB vs. Cache vs. ...), although it still would not give per-database or per-object store values.

发布评论

评论列表(0)

  1. 暂无评论