Skip to content
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

Merged
merged 10 commits into from
Jun 6, 2024
Merged

More APIs for Student Information #18

merged 10 commits into from
Jun 6, 2024

Conversation

shadinaif
Copy link
Collaborator

More APIs for Student Information

@shadinaif shadinaif force-pushed the shadinaif/more-apis branch 4 times, most recently from 4c47b38 to b1ee08f Compare May 27, 2024 14:58
@shadinaif shadinaif marked this pull request as ready for review May 27, 2024 15:02
@shadinaif shadinaif force-pushed the shadinaif/more-apis branch from b1ee08f to be58b87 Compare May 27, 2024 17:55
Ensure the user is passed as User object and not its ID
get_block_structure_manager expects a string course key
@shadinaif shadinaif force-pushed the shadinaif/more-apis branch 3 times, most recently from d0de299 to 41c54c6 Compare May 29, 2024 15:53
@shadinaif shadinaif requested a review from OmarIthawi June 4, 2024 15:26
@OmarIthawi
Copy link
Collaborator

Thanks @shadinaif! We'll deploy the tag and keep this pull request for review. @iamjazzar will review it today.

Copy link

@iamjazzar iamjazzar left a 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)

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?

Copy link
Collaborator Author

@shadinaif shadinaif Jun 5, 2024

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

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

@iamjazzar iamjazzar Jun 4, 2024

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.

Copy link
Collaborator Author

@shadinaif shadinaif Jun 5, 2024

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

futurex_openedx_extensions/dashboard/serializers.py Outdated Show resolved Hide resolved
@shadinaif shadinaif force-pushed the shadinaif/more-apis branch from 41c54c6 to f029f11 Compare June 5, 2024 15:31
@shadinaif
Copy link
Collaborator Author

Thank you for the review @iamjazzar , please take a look now

Copy link

@iamjazzar iamjazzar left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@shadinaif shadinaif merged commit 16fea5c into main Jun 6, 2024
3 checks passed
@shadinaif shadinaif deleted the shadinaif/more-apis branch June 6, 2024 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants