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.

stsewd added 2 commits Aug 30, 2019
This is going to help us to extend this view more easily
from the corporate site.
readthedocs/api/v2/views/footer_views.py Show resolved Hide resolved
Loading
readthedocs/api/v2/views/footer_views.py Show resolved Hide resolved
Loading
@stsewd stsewd requested review from ericholscher and Aug 30, 2019
Copy link
Member

@ericholscher ericholscher left a comment

Good refactor 👍

Loading

readthedocs/api/v2/views/footer_views.py Show resolved Hide resolved
Loading
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

@ericholscher ericholscher Aug 30, 2019

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.

Loading

Copy link
Member Author

@stsewd stsewd Aug 30, 2019

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.

Loading

Copy link
Member Author

@stsewd stsewd Aug 30, 2019

Choose a reason for hiding this comment

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

Loading

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

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

@humitos humitos Sep 4, 2019

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.

Loading

Copy link
Member

@ericholscher ericholscher Sep 5, 2019

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.

Loading

Copy link
Member

@humitos humitos Sep 5, 2019

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

Loading

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

Successfully merging this pull request may close these issues.

None yet

3 participants