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

Fix staleness bug for application export #722

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

julianweng
Copy link
Member

Currently, the CSV export for applications relies on its own (Django built-in) cache, which results in staleness. This is especially an issue when club leaders export applications shortly (< 2 hours) after an application is due, as the export would not include many application submissions that were recently submitted.

This PR makes the route use the viewset list() function, which has valid manual caching and related invalidations on application submission. It also refactors list() to cache the non-serialized data to facilitate this.

Copy link
Member

@aviupadhyayula aviupadhyayula 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 taking the initiative Julian. Left a comment.

qs = self.get_queryset()
cache.set(key, qs, 60 * 60)
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason we're caching the queryset instead of the data?

Copy link
Member Author

Choose a reason for hiding this comment

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

We only get the data after running the queryset through the serializer, while I wanted the cache contents itself to be serializer agnostic given that export uses a different serializer. On second thought though, get_queryset() might be evaluated lazily so I would need to rethink this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you think .objects.all() would work @aviupadhyayula?

Copy link
Member

@aviupadhyayula aviupadhyayula Sep 10, 2024

Choose a reason for hiding this comment

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

From what I've read, it looks like the Django caching library forces evaluation upon insertion. We can test this later (force Django to log each query evaluation in settings). I'm more concerned about breaking our pattern of not caching querysets anywhere.

Honestly, is there a reason to cache this view? Querying the list of applicants will be done very rarely. Some latency on invocation is preferable to leaving a couple applicants off the UI or downloaded CSV. Not caching also obviates this concern.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's fair, caching definitely isn't necessary, at least for the CSV export (I didn't know that clubs used this feature until very recently). However, the cache invalidation logic was already previously written for the list view, and application-related views also contribute to site-level performance (I'm not sure how strict our transaction isolation levels are if at all, but you could imagine that querying all applications repeatedly, especially while new upsert transactions could still occur, is bad during application season).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants