-
Notifications
You must be signed in to change notification settings - Fork 192
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 #609 - Implements HTTP Caching for HTML routes #1335
Conversation
ok let's ask |
webcompat/views.py
Outdated
content = render_template('issue.html', number=number) | ||
response = make_response(content) | ||
# We can cache for one year. Etag is based on the content. | ||
response = set_cache_control(response, 31536000) |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
Let me deploy this to staging so you can play around with it. I won't have time for review until tomorrow. |
🍪 for new tests! |
@karlcow deployed to staging. |
Thanks @miketaylr https://staging.webcompat.com/issues/515 HTTP/1.1 200 OK
Server: nginx/1.1.19
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
Cache-Control: private, max-age=31536000
Etag: "f9530168e98a2537ad066564ef2f38e5"
Date: Fri, 10 Feb 2017 01:09:30 GMT
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Content-Type-Options: nosniff
x-xss-protection: 1; mode=block
x-frame-options: DENY
Content-Encoding: gzip Click reload Request GET /issues/515 HTTP/1.1
Host: staging.webcompat.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:54.0) Gecko/20100101 Firefox/54.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Referer: https://staging.webcompat.com/
Cookie: session=****; _ga=GA1.2.1918118046.1486688948; _gat=1
Authorization: Basic czpz
Connection: keep-alive
Upgrade-Insecure-Requests: 1
If-None-Match: "f9530168e98a2537ad066564ef2f38e5"
Cache-Control: max-age=0 Response HTTP/1.1 304 NOT MODIFIED
Server: nginx/1.1.19
Connection: keep-alive
Cache-Control: private, max-age=31536000
Etag: "f9530168e98a2537ad066564ef2f38e5"
Date: Fri, 10 Feb 2017 01:12:03 GMT
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Content-Type-Options: nosniff
x-xss-protection: 1; mode=block
x-frame-options: DENY So this is working as expected. \o/ |
I'm changing a bit the strategy to have more flexbility for other resources/routes. I created a decorator defining the cache_policy The routes without caching
|
Don't review yet :) |
Deal! |
webcompat/helpers.py
Outdated
|
||
Adds Cache-Control headers. | ||
Adds Etag based on HTTP Body. | ||
Sends a 304 Not Modified in cas of If-None-Match. |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
Let's start a formal review r? @miketaylr |
webcompat/db/__init__.py
Outdated
@@ -45,6 +45,7 @@ def __init__(self, issue_id, summary, url, body): | |||
self.url = url | |||
self.body = body | |||
|
|||
|
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
webcompat/helpers.py
Outdated
@@ -456,3 +459,29 @@ def api_request(method, path, params=None, data=None): | |||
get_response_headers(resource)) | |||
else: | |||
abort(404) | |||
|
|||
|
|||
def cache_policy(private=True, uri_max_age=3600): |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
return render_template('issue.html', number=number) | ||
content = render_template('issue.html', number=number) | ||
response = make_response(content) | ||
return response |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
@@ -143,6 +144,7 @@ def index(): | |||
|
|||
|
|||
@app.route('/issues') | |||
@cache_policy(private=True, uri_max_age=86400) |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
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.
Looks good!
One or two minor nits that are up to you, but it would be good to add the requested comments.
One other thing: can you clean up the history here? 17 commits is a bit much for what we're adding.
For example, all the test commits could be squashed into a single "tests for http caching" commit. And there's a few commits that add an idea (8cc5446) (512a68c), then remove that idea (47f18dc), etc.
A commit style like that is GOOD for development, but we can just land the working loaf of bread that you baked, rather than the breadcrumbs (if that makes sense, it's a terrible metaphor).
Issue webcompat#609 - Removes code dust
@miketaylr Ok I squashed everything into one commit. :) because rebasing with intertwined modifications was probably not a good idea. If you prefer I can submit separate commits for testing, decorator and views in a new branch. ^_^ No issue. |
That's fine too. Doing gigantic interactive rebases can easily get weird. |
r=me, assuming you'll make the |
It was done no? So assuming that @miketaylr had missed the change I'll move forward. Thanks for the review! Very helpful. |
I wasn't even looking -- I assumed you would merge it after you made the change. 😄 Happy this landed! |
This currently doesn't fix all HTML resources served on our site, but just the issue view.
I would love to get it on staging, because of our nginx layer and see how it flies. Locally, things seem to go well.
And on the CLI.
First request:
The 1st response
Then the second request with
If-None-Match
with the second response: