aboutsummaryrefslogtreecommitdiff
path: root/gn3/db
diff options
context:
space:
mode:
authorMunyoki Kilyungi2023-03-01 15:46:13 +0300
committerBonfaceKilz2023-03-01 22:03:39 +0300
commite32dacc9648908a73855d99e7681cb4d7aa4f98e (patch)
tree51faa8bb4aa94fae684f49ea8bc9552bef9222ae /gn3/db
parent104723d9954359cbc10140c36d4ae4f8d2f4f7f4 (diff)
downloadgenenetwork3-e32dacc9648908a73855d99e7681cb4d7aa4f98e.tar.gz
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 <me@bonfacemunyoki.com>
Diffstat (limited to 'gn3/db')
-rw-r--r--gn3/db/matrix.py6
1 files changed, 3 insertions, 3 deletions
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""