-
Notifications
You must be signed in to change notification settings - Fork 0
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
More APIs for Student Information #18
Conversation
Refactor (only_visible and only_active) to (visible_filter and active_filter)
4c47b38
to
b1ee08f
Compare
b1ee08f
to
be58b87
Compare
Ensure the user is passed as User object and not its ID
get_block_structure_manager expects a string course key
ensure Grade is read as JSON
d0de299
to
41c54c6
Compare
Thanks @shadinaif! We'll deploy the tag and keep this pull request for review. @iamjazzar will review it today. |
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.
I took a stab at it. The query sets seem alright, but they're written in a style that's a bit unfamiliar to me, so I can't suggest a refactor right off the bat. I've made some suggestions for refactoring and raised a few points.
) if callable(key_generator_or_name) else key_generator_or_name | ||
|
||
except Exception as exc: # pylint: disable=broad-except | ||
log.exception("cache_dict: error generating cache key: %s", exc) |
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.
It seems this code logs the error and continues. Would it be better to raise an exception here to halt execution and signal the issue?
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.
Since the code allows key_generator_or_name
to be callable
or str
; it can fail because of a silly key generation mistake. I've tested my generators, but I mean if a new one is used without proper testing; I don't want it to block the execution of the APIs. An error message that will popup many times in the logs will be enough to draw the attention
I prefer keeping it passing without interrupting the API execution. This means we'll lose only the cache; not the entire response
What do you think @iamjazzar ?
I would also appreciate your feedback @OmarIthawi
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.
Makes sense @shadinaif
result = cache.get(cache_key) if cache_key else None | ||
if result is None: | ||
result = func(*args, **kwargs) | ||
if cache_key and result and isinstance(result, dict): |
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 brings up an interesting point about caching empty dictionaries ({}
). Caching the results of expensive functions (like a 200ms web query that can return empty results) can definitely improve performance.
However, it's worth considering the implications:
- Cache invalidation: If the function's result can change over time (e.g., the web query might return a value later), we need a way to invalidate the cache to ensure we fetch fresh data.
- Memory overhead: Even empty dictionaries consume some memory. If caching empties is frequent, the memory usage can add up.
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.
Good point @iamjazzar . I'll keep this in mind! currently, I'm using it for only two functions that are being used too many times with small result sizes --- empty dict
is not possible for these two
41c54c6
to
f029f11
Compare
Thank you for the review @iamjazzar , please take a look now |
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.
LGTM 👍
More APIs for Student Information