-
Notifications
You must be signed in to change notification settings - Fork 13
feat: Add cache layer for the datastore adapter #1514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
phorward
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for facing this.
I'm a little bit astonished how bloated this code is, especially regarding this multiple-key feature. Is this anywhere used in ViUR, except in legacy code?
Anyway. I think this code might be improved in the cache-module, too.
My recommendation: When code that either handles one or a list of keys is written, write the code as it always handles a list of keys, so that the len(keys) == 1-case becomes the special case. This eliminates lots of bloating regarding isinstance()-checks and iterable-checking.
Can you please test my suggestions, and please don't forget to import utils to use ensure_iterable.
Co-authored-by: Jan Max Meyer <[email protected]>
|
@phorward we can not use |
The previous solution was because SortIndex was in viur-datastore previously.
I've fixed that and also a a bug and update the code to use |
| if not isinstance(keys, (tuple, list, set)): | ||
| keys = (keys,) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if not isinstance(keys, (tuple, list, set)): | |
| keys = (keys,) | |
| keys = utils.ensure_iterable(keys) |
| keys = keys[MEMCACHE_MAX_BATCH_SIZE:] | ||
| except Exception as e: | ||
| logging.error(f"""Failed to get keys form the memcache with {e=}""") | ||
| for key, value in cached_data.items(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cached data might be uninizialized!
| logging.error(f"""Failed to get keys form the memcache with {e=}""") | ||
| for key, value in cached_data.items(): | ||
| entity = Entity(Key(key)) | ||
| entity = Entity(Key.from_legacy_urlsafe(key)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these always str-keys?
| if not isinstance(keys, (tuple, list, set)): | ||
| keys = (keys,) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if not isinstance(keys, (tuple, list, set)): | |
| keys = (keys,) | |
| keys = utils.ensure_iterable(keys) |
| if not isinstance(keys, (tuple, list, set)): | ||
| keys = (keys,) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if not isinstance(keys, (tuple, list, set)): | |
| keys = (keys,) | |
| keys = utils.ensure_iterable(keys) |
| if not keys: | ||
| return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is tested twice, the keys list cannot be empty when coming to this line
| if not keys: | |
| return |
No description provided.