realm-js icon indicating copy to clipboard operation
realm-js copied to clipboard

Provide way to access DB totalSize/usedSize outside of `shouldCompactOnLaunch` callback

Open liamjones opened this issue 2 years ago • 4 comments

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 avatar Feb 18 '22 09:02 liamjones

@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

kraenhansen avatar Feb 22 '22 10:02 kraenhansen

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?

liamjones avatar Feb 22 '22 10:02 liamjones

I agree, something like this would also work?

const realm = new Realm();
const { total, used } = realm.size;
console.log(total, used); // bytes

kraenhansen avatar Feb 22 '22 11:02 kraenhansen

@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.

kneth avatar May 15 '23 13:05 kneth