From 937adbf439053cabe7b7c2e350ca74906ae61a7c Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Fri, 11 Feb 2022 15:49:09 -0500 Subject: [PATCH] add `estimate_num_keys` to prefix interface --- lbry/wallet/server/db/interface.py | 3 +++ lbry/wallet/server/db/prefixes.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/lbry/wallet/server/db/interface.py b/lbry/wallet/server/db/interface.py index 79475a240..465b1f01a 100644 --- a/lbry/wallet/server/db/interface.py +++ b/lbry/wallet/server/db/interface.py @@ -139,3 +139,6 @@ class BasePrefixDB: def stage_raw_delete(self, key: bytes, value: bytes): self._op_stack.append_op(RevertableDelete(key, value)) + + def estimate_num_keys(self, column_family: 'rocksdb.ColumnFamilyHandle' = None): + return int(self._db.get_property(b'rocksdb.estimate-num-keys', column_family).decode()) diff --git a/lbry/wallet/server/db/prefixes.py b/lbry/wallet/server/db/prefixes.py index 26b105ec0..b88d31551 100644 --- a/lbry/wallet/server/db/prefixes.py +++ b/lbry/wallet/server/db/prefixes.py @@ -144,6 +144,9 @@ class PrefixRow(metaclass=PrefixRowType): def unpack_item(cls, key: bytes, value: bytes): return cls.unpack_key(key), cls.unpack_value(value) + def estimate_num_keys(self) -> int: + return int(self._db.get_property(b'rocksdb.estimate-num-keys', self._column_family).decode()) + class UTXOKey(NamedTuple): hashX: bytes