Skip to content

Commit

Permalink
levels.read touches now
Browse files Browse the repository at this point in the history
  • Loading branch information
talgat committed Oct 25, 2023
1 parent 56bfec3 commit 16ee0c9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion tarn/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.13.1'
__version__ = '0.13.2'
32 changes: 15 additions & 17 deletions tarn/location/levels.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,22 @@ def __init__(self, *levels: Union[Level, Location]):

@contextmanager
def read(self, key: Key, return_labels: bool) -> ContextManager[Union[None, Value, Tuple[Value, MaybeLabels]]]:
read = False
for index, config in enumerate(self._levels):
leave = False
with config.location.read(key, True) as value:
if value is not None:
# we must leave the loop after the first successful read
leave = True
# try to write to a level with higher priority
with self._replicate(key, *value, index) as (value_copy, labels_copy):
if return_labels:
yield value_copy, labels_copy
else:
yield value_copy

# but the context manager might have silenced the error, so we need an extra return here
if leave:
return

yield None
if not read:
with config.location.read(key, True) as value:
if value is not None:
read = True
# try to write to a level with higher priority
with self._replicate(key, *value, index) as (value_copy, labels_copy):
if return_labels:
yield value_copy, labels_copy
else:
yield value_copy
else:
config.location.touch(key)
if not read:
yield None

@contextmanager
def write(self, key: Key, value: Value, labels: MaybeLabels) -> ContextManager[MaybeValue]:
Expand Down

0 comments on commit 16ee0c9

Please sign in to comment.