-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Refactor footer_html view to class #6125
Refactor footer_html view to class #6125
Conversation
This is going to help us to extend this view more easily from the corporate site.
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 refactor 👍
if not project: | ||
project_slug = self.request.GET.get('project', None) | ||
project = get_object_or_404(Project, slug=project_slug) | ||
setattr(self, cache_key, project) |
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.
Should we actually be using the real Django cache, and caching these across lookups? That would make it so we never have to hit the DB in the footer in normal cases.
Probably doesn't make sense, but worth a thought.
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.
Do you mean cache the view or the model? I'm opening a new issue to follow 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.
renderer_classes = [JSONRenderer, JSONPRenderer] | ||
|
||
def _get_project(self): | ||
cache_key = '_cached_project' |
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.
These cache keys should have a more specific prefix, like: footerhtml_cached_project
. Otherwise, it's easy to override by mistake.
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's an attribute on the class, so it's naturally scoped I think.
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.
Oh, right. We will need to change it if we move into a shared cache as you suggested, though
This is going to help us to extend this view more easily
from the corporate site.
Logic is the same, just code was moved.