Commit 31706e46 authored by ale's avatar ale

do not cache sqlalchemy objects until we find a way of doing it correctly

parent ad9d5b09
......@@ -64,30 +64,17 @@ class VideoController(BaseController):
def list(self, what, arg=None):
"""List videos according to several criteria specified by the
'what' argument (and, eventually, the 'arg' parameter).
If the user is not logged in, the response is cached.
if what == 'queue' \
and not (h.logged_in() and h.in_group('reviewers')):
return 'Unauthorized.'
# the full videos list is kept into cache for normal users
def list_videos_fn():
res = model.VideoQuery.query([(what, arg)])
return (res.query.all(), res.title, res.count)
if not h.logged_in():
v_cache = cache.get_cache('videos')
all_videos, c.title, num_videos = v_cache.get_value(
'%s/%s' % (what, arg or '_'),
all_videos, c.title, num_videos = list_videos_fn()
res = model.VideoQuery.query([(what, arg)])
# paginate the videos
page_num = int(request.params.get('p', 0))
c.videos = h.Page(
all_videos, item_count=num_videos,
res.query, item_count=res.count,
page=page_num, items_per_page=10)
c.title = res.title
c.what = what
c.arg = arg
c.page_num = page_num
......@@ -96,22 +83,15 @@ class VideoController(BaseController):
def rss(self, what, arg=None):
"""Similar to list, render an RSS 2.0 feed. The caching
strategy is also simpler."""
def list_videos_fn():
res = model.VideoQuery.query([(what, arg)])
videos = res.query.order_by([desc(model.Video.publication_date)]).limit(15).all()
etag = md5.md5(u''.join([x.title for x in videos]).encode('utf-8')).hexdigest()
return (etag, videos, res.count, res.title)
v_cache = cache.get_cache('rss_videos')
cache_key = "%s/%s" % (what, arg or '_')
etag, c.videos, count, c.title = v_cache.get_value(
res = model.VideoQuery.query([(what, arg)])
c.videos = res.query.order_by([desc(model.Video.publication_date)]).limit(15).all()
c.title = rest.title
etag = md5.md5(u''.join([x.title for x in videos]).encode('utf-8')).hexdigest()
response.headers['Expires'] = h.httpdate( + timedelta(1))
response.headers['Last-Modified'] = h.httpdate(c.videos[0].publication_date)
response.headers['Content-Type'] = 'application/rss+xml'
cache_key = "%s/%s" % (what, arg or '_')
return render('video/rss.html', cache_key=cache_key, cache_expire=900)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment