Skip to content

Commit

Permalink
Merge pull request #63 from neuro-ml/dev
Browse files Browse the repository at this point in the history
600x redis speed boost
  • Loading branch information
STNLd2 authored Oct 20, 2023
2 parents f871bf5 + 56bfec3 commit 99ccc80
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 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.0'
__version__ = '0.13.1'
32 changes: 17 additions & 15 deletions tarn/location/levels.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,29 @@ def read(self, key: Key, return_labels: bool) -> ContextManager[Union[None, Valu
def write(self, key: Key, value: Value, labels: MaybeLabels) -> ContextManager[MaybeValue]:
for config in self._levels:
location = config.location
if is_binary_io(value):
offset = value.tell()
leave = False
with location.write(key, value, labels) as written:
if written is not None:
# we must leave the loop after the first successful write
leave = True
yield written
# but the context manager might have silenced the error, so we need an extra return here
if leave:
return
if is_binary_io(value) and offset != value.tell():
value.seek(offset)
if config.write:
if is_binary_io(value):
offset = value.tell()
leave = False
with location.write(key, value, labels) as written:
if written is not None:
# we must leave the loop after the first successful write
leave = True
yield written
# but the context manager might have silenced the error, so we need an extra return here
if leave:
return
if is_binary_io(value) and offset != value.tell():
value.seek(offset)

yield None

def delete(self, key: Key) -> bool:
deleted = False
for config in self._levels:
if config.location.delete(key):
deleted = True
if config.write:
if config.location.delete(key):
deleted = True

return deleted

Expand Down
3 changes: 0 additions & 3 deletions tarn/location/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,6 @@ def _get_usage_date(self, key: Key) -> Optional[datetime]:
return datetime.fromtimestamp(float(usage_date))

def touch(self, key: Key):
content_key = self.prefix + key
if content_key not in self.redis.keys():
return False
usage_date_key = b'usage_date' + self.prefix + key
self.redis.set(usage_date_key, datetime.now().timestamp())
return True
Expand Down

0 comments on commit 99ccc80

Please sign in to comment.