diff --git a/pantherdb/__init__.py b/pantherdb/__init__.py index efebc10..3df0104 100644 --- a/pantherdb/__init__.py +++ b/pantherdb/__init__.py @@ -1,6 +1,6 @@ from pantherdb.pantherdb import * # noqa: F403 -__version__ = '1.3.3' +__version__ = '1.3.4' __all__ = ('__version__', 'PantherDB', 'PantherCollection', 'PantherDocument', 'PantherDBException') diff --git a/pantherdb/pantherdb.py b/pantherdb/pantherdb.py index 4f768b6..2d1ff23 100644 --- a/pantherdb/pantherdb.py +++ b/pantherdb/pantherdb.py @@ -82,22 +82,22 @@ def _write(self) -> None: file.write(content) def _refresh(self) -> None: - # TODO: Find Solution, so won't refresh on every single query with open(self.db_name, 'rb') as file: + data = file.read() - if not (data := file.read()): - self.__content = {} + if not data: + self.__content = {} - elif not self.secret_key: - self.__content = json.loads(data) + elif not self.secret_key: + self.__content = json.loads(data) - else: - try: - decrypted_data: bytes = self.__fernet.decrypt(data) - self.__content = json.loads(decrypted_data) - except InvalidToken: - error = '"secret_key" Is Not Valid' - raise PantherDBException(error) + else: + try: + decrypted_data: bytes = self.__fernet.decrypt(data) + self.__content = json.loads(decrypted_data) + except InvalidToken: + error = '"secret_key" Is Not Valid' + raise PantherDBException(error) def collection(self, collection_name: str) -> PantherCollection: return PantherCollection(