aboutsummaryrefslogtreecommitdiff
path: root/gn3/db
diff options
context:
space:
mode:
authorMunyoki Kilyungi2023-02-06 14:40:04 +0300
committerBonfaceKilz2023-02-06 18:14:19 +0300
commitfaf223207015077d0afc36c7cc7cf1fc29976c7f (patch)
treeaa0d73863272d8ed32cdd32267ae8919a1696076 /gn3/db
parent8bfb1f9e9f74f41eb251eb025838244cc5c256eb (diff)
downloadgenenetwork3-faf223207015077d0afc36c7cc7cf1fc29976c7f.tar.gz
Get total number of versions that a database has
* gn3/db/matrix.py (get_total_versions): New function. Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
Diffstat (limited to 'gn3/db')
-rw-r--r--gn3/db/matrix.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/gn3/db/matrix.py b/gn3/db/matrix.py
index d40f3c3..71e7ca0 100644
--- a/gn3/db/matrix.py
+++ b/gn3/db/matrix.py
@@ -17,6 +17,15 @@ class Matrix:
metadata: dict
+def get_total_versions(db_path: str) -> int:
+ """Get the total number of versions in the matrix"""
+ env = lmdb.open(db_path)
+ with env.begin(write=False) as txn:
+ versions_hash = txn.get(b"versions")
+ if not versions_hash:
+ return 0
+ return int(len(versions_hash) / BLOB_HASH_DIGEST)
+
def get_current_matrix(db_path: str) -> Optional[Matrix]:
"""Get the most recent matrix from DB_PATH. This is functionally
equivalent to get_nth_matrix(0, db_path)"""
@@ -28,7 +37,6 @@ def get_current_matrix(db_path: str) -> Optional[Matrix]:
nrows = 0
if matrix_hash:
(nrows,) = struct.unpack("<Q", txn.get(matrix_hash + b":nrows"))
- data, metadata = None, None
if row_pointers:
return Matrix(
data=[