realm-js
realm-js copied to clipboard
Provide way to access DB totalSize/usedSize outside of `shouldCompactOnLaunch` callback
Problem
We want to start tracking the size of our user's realm DBs so we can come up with a strategy for when compaction occurs based on DB sizes we see in the wild.
We can do this via the shouldCompactOnLaunch
callback but that's not really the place we want to retrieve the information.
It'd be nice if there was a way to retrieve the total/used sizes on an already opened DB.
Solution
No response
How important is this improvement for you?
I'd like to see it, but have a workaround
@liamjones thanks for reporting this, I've moved it to our backlog.
What would be a good API for this?
I suggest exposing these as properties on the Realm
instance:
const realm = new Realm();
console.log(realm.totalSize, realm.usedSize); // bytes
Something simple like that sounds good.
Maybe you'd want to combine the two into a single object since they're so interrelated?
I'm guessing the properties would be dynamic? E.g. current size is looked up and reported at access time?
I agree, something like this would also work?
const realm = new Realm();
const { total, used } = realm.size;
console.log(total, used); // bytes
@liamjones In Realm JavaScript v11.3.0 we introduce online compaction i.e., Realm files will be compacted during commits.
The proposed feature is valuable but we believe you will less frequent need to compact.