Skip to content

Commit

Permalink
Set autocommit for memoize to db
Browse files Browse the repository at this point in the history
  • Loading branch information
cevans87 committed Jan 1, 2020
1 parent caedc56 commit c1e4d58
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
5 changes: 1 addition & 4 deletions atools/_memoize_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class _MemoizeBase:

def __post_init__(self) -> None:
if self.db is not None:
self.db.isolation_level = None
return_annotation = inspect.signature(self.fn).return_annotation
if not hasattr(return_annotation, '__name__'):
object.__setattr__(self, 'db_eval_types', dict(self.fn.__globals__))
Expand Down Expand Up @@ -106,7 +107,6 @@ def __post_init__(self) -> None:
f"SELECT k, t0 FROM `{self.table_name}` ORDER BY t0"
).fetchall():
self.expire_order[k] = ...
self.db.commit()

def __len__(self) -> int:
return len(self.memos)
Expand Down Expand Up @@ -162,7 +162,6 @@ def expire_one_memo(self) -> None:
(k, _) = self.memos.popitem(last=False)
if (self.db is not None) and (k is not None):
self.db.execute(f"DELETE FROM `{self.table_name}` WHERE k = '{k}'")
self.db.commit()

def finalize_memo(self, memo: _Memo, key: Union[int, str]) -> Any:
if memo.memo_return_state.raised:
Expand All @@ -185,7 +184,6 @@ def finalize_memo(self, memo: _Memo, key: Union[int, str]) -> Any:
value
)
)
self.db.commit()
return memo.memo_return_state.value

def get_hashed_key(self, key: Tuple[Hashable]) -> Union[int, str]:
Expand All @@ -205,7 +203,6 @@ def reset(self) -> None:
object.__setattr__(self, 'memos', OrderedDict())
if self.db is not None:
self.db.execute(f"DELETE FROM `{self.table_name}`")
self.db.commit()

def reset_key(self, key: Union[int, str]) -> None:
if key in self.memos:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='atools',
version='0.10.3',
version='0.10.4',
packages=find_packages(),
python_requires='>=3.6',
url='https://github.com/cevans87/atools',
Expand Down

0 comments on commit c1e4d58

Please sign in to comment.