mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-28 00:07:57 -05:00
move last_modified fields into memcache db
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user