Skip to content

Conversation

@ArneGudermann
Copy link
Contributor

No description provided.

@ArneGudermann ArneGudermann added feature New feature or request performance This issue or pull request enhances or criticizes the performance. labels Jul 9, 2025
@ArneGudermann ArneGudermann added this to the ViUR-core v3.8 milestone Jul 9, 2025
Copy link
Member

@phorward phorward left a 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.

@ArneGudermann
Copy link
Contributor Author

@phorward we can not use utils due a circular import

@ArneGudermann ArneGudermann requested a review from phorward July 11, 2025 10:12
@phorward
Copy link
Member

@phorward we can not use utils due a circular import

I've fixed that and also a a bug and update the code to use utils.ensure_iterable() can you please have a look and - if you have test-cases - test it?

Comment on lines +52 to +53
if not isinstance(keys, (tuple, list, set)):
keys = (keys,)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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():
Copy link
Member

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))
Copy link
Member

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?

Comment on lines +127 to +128
if not isinstance(keys, (tuple, list, set)):
keys = (keys,)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if not isinstance(keys, (tuple, list, set)):
keys = (keys,)
keys = utils.ensure_iterable(keys)

Comment on lines +109 to +110
if not isinstance(keys, (tuple, list, set)):
keys = (keys,)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if not isinstance(keys, (tuple, list, set)):
keys = (keys,)
keys = utils.ensure_iterable(keys)

Comment on lines +112 to +113
if not keys:
return
Copy link
Member

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

Suggested change
if not keys:
return

@phorward phorward added Priority: High After critical issues are fixed, these should be dealt with before any further issues. viur-meeting Issues to discuss in the next ViUR meeting labels Jul 17, 2025
@phorward phorward removed the viur-meeting Issues to discuss in the next ViUR meeting label Jul 21, 2025
@phorward phorward self-requested a review July 21, 2025 20:58
@phorward phorward added Priority: Medium This issue may be useful, and needs some attention. and removed Priority: High After critical issues are fixed, these should be dealt with before any further issues. labels Jul 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request performance This issue or pull request enhances or criticizes the performance. Priority: Medium This issue may be useful, and needs some attention.

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants