From e32dacc9648908a73855d99e7681cb4d7aa4f98e Mon Sep 17 00:00:00 2001 From: Munyoki Kilyungi Date: Wed, 1 Mar 2023 15:46:13 +0300 Subject: Open lmdb path in readonly mode * gn3/db/matrix.py (get_total_versions, get_nth_matrix, get_current_matrix): Open lmdb in readonly mode. Signed-off-by: Munyoki Kilyungi --- gn3/db/matrix.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'gn3') diff --git a/gn3/db/matrix.py b/gn3/db/matrix.py index 0fc4bf4..24825f9 100644 --- a/gn3/db/matrix.py +++ b/gn3/db/matrix.py @@ -19,7 +19,7 @@ class Matrix: def get_total_versions(db_path: str) -> int: """Get the total number of versions in the matrix""" - env = lmdb.open(db_path) + env = lmdb.open(db_path, readonly="True") with env.begin(write=False) as txn: versions_hash = txn.get(b"versions") if not versions_hash: @@ -29,7 +29,7 @@ def get_total_versions(db_path: str) -> int: def get_nth_matrix(index: int, db_path: str) -> Optional[Matrix]: """Get the NTH matrix from the DB_PATH. The most recent matrix is 0.""" - env = lmdb.open(db_path) + env = lmdb.open(db_path, readonly="True") with env.begin(write=False) as txn: versions_hash = txn.get(b"versions") if (index * 32) + 32 > len(versions_hash): @@ -54,7 +54,7 @@ def get_nth_matrix(index: int, db_path: str) -> Optional[Matrix]: 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)""" - env = lmdb.open(db_path) + env = lmdb.open(db_path, readonly="True") with env.begin(write=False) as txn: current_hash = txn.get(b"current") or b"" matrix_hash = txn.get(current_hash + b":matrix") or b"" -- cgit v1.2.3