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

Refactor footer_html view to class #6125

Merged
merged 4 commits into from
Aug 30, 2019

Conversation

stsewd
Copy link
Member

@stsewd stsewd commented Aug 30, 2019

This is going to help us to extend this view more easily
from the corporate site.

Logic is the same, just code was moved.

This is going to help us to extend this view more easily
from the corporate site.
@stsewd stsewd requested review from ericholscher and a team August 30, 2019 01:07
Copy link
Member

@ericholscher ericholscher left a comment

Choose a reason for hiding this comment

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

Good refactor 👍

readthedocs/api/v2/views/footer_views.py Show resolved Hide resolved
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)
Copy link
Member

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.

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 mean cache the view or the model? I'm opening a new issue to follow up.

Copy link
Member Author

Choose a reason for hiding this comment

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

readthedocs/api/v2/views/footer_views.py Show resolved Hide resolved
@stsewd stsewd mentioned this pull request Aug 30, 2019
@stsewd stsewd merged commit 34d1a15 into readthedocs:master Aug 30, 2019
@stsewd stsewd deleted the stsewd/refactor-footer-html-view branch August 30, 2019 02:20
renderer_classes = [JSONRenderer, JSONPRenderer]

def _get_project(self):
cache_key = '_cached_project'
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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

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