diff --git a/r2/r2/controllers/api.py b/r2/r2/controllers/api.py index 53aa13514..26d7552fd 100644 --- a/r2/r2/controllers/api.py +++ b/r2/r2/controllers/api.py @@ -241,6 +241,7 @@ class ApiController(RedditController): #update the modified flags set_last_modified(c.user, 'overview') set_last_modified(c.user, 'submitted') + set_last_modified(c.user, 'liked') # flag search indexer that something has changed tc.changed(l) diff --git a/r2/r2/controllers/reddit_base.py b/r2/r2/controllers/reddit_base.py index d2195a06f..597d36aa5 100644 --- a/r2/r2/controllers/reddit_base.py +++ b/r2/r2/controllers/reddit_base.py @@ -574,7 +574,7 @@ class RedditController(BaseController): return date = utils.is_modified_since(thing, action, request.if_modified_since) - if date is True: + if date is False: abort(304, 'not modified') else: c.response.headers['Last-Modified'] = http_utils.http_date_str(date) diff --git a/r2/r2/lib/utils/thing_utils.py b/r2/r2/lib/utils/thing_utils.py index 62c9cdedb..bc89e6146 100644 --- a/r2/r2/lib/utils/thing_utils.py +++ b/r2/r2/lib/utils/thing_utils.py @@ -6,27 +6,30 @@ def make_last_modified(): last_modified = last_modified.replace(microsecond = 0) return last_modified +def last_modified_key(thing, action): + return 'last_' + action + '_' + thing._fullname + def is_modified_since(thing, action, date): """Returns true if the date is older than the last_[action] date, which means a 304 should be returned. Otherwise returns the date that should be sent as the last-modified header.""" from pylons import g + cache = g.permacache - prop = 'last_' + action - if not hasattr(thing, prop): + key = last_modified_key(thing, action) + last_modified = cache.get(key) + if not last_modified: + #if there is no last_modified, add one last_modified = make_last_modified() - setattr(thing, prop, last_modified) - thing._commit() - else: - last_modified = getattr(thing, prop) + cache.set(key, last_modified) if not date or date < last_modified: return last_modified - - #if a date was passed in and it's equal to last modified - return True + else: + #if a date was passed in and it's >= to last modified + return False def set_last_modified(thing, action): from pylons import g - setattr(thing, 'last_' + action, make_last_modified()) - thing._commit() + key = last_modified_key(thing, action) + g.permacache.set(key, make_last_modified())