Made _getPickData more generic by supporting ordening
As such, renamed it to _getData.
Also use a more robust way to represent the filter in case it
contains entities.
Patch by: Sverre Rabbelier
--- a/app/soc/cache/logic.py Fri Mar 20 21:01:49 2009 +0000
+++ b/app/soc/cache/logic.py Fri Mar 20 21:02:21 2009 +0000
@@ -23,23 +23,33 @@
from google.appengine.api import memcache
+from google.appengine.ext import db
import soc.cache.base
-def key(model, filter):
+def key(model, filter, order):
"""Returns the memcache key for this query.
"""
- return 'query_for_%s_%s' % (repr(model.kind()), repr(filter))
+ new_filter = {}
+
+ for key, value in filter.iteritems():
+ new_value = value.key().name() if isinstance(value, db.Model) else value
+ new_filter[key] = new_value
+
+ return 'query_for_%(kind)s_%(filter)s_%(order)s' % {
+ 'kind': repr(model.kind()),
+ 'filter': repr(new_filter),
+ 'order': repr(order),
+ }
-def get(model, filter, *args, **kwargs):
+def get(model, filter, order, *args, **kwargs):
"""Retrieves the data for the specified query from the memcache.
"""
- memcache_key = key(model, filter)
- import logging; logging.info(memcache_key)
+ memcache_key = key(model, filter, order)
return memcache.get(memcache_key), memcache_key
@@ -52,7 +62,6 @@
# Store data for fifteen minutes to force a refresh every so often
retention = 15*60
-
memcache.add(memcache_key, data, retention)
--- a/app/soc/views/models/base.py Fri Mar 20 21:01:49 2009 +0000
+++ b/app/soc/views/models/base.py Fri Mar 20 21:02:21 2009 +0000
@@ -653,7 +653,7 @@
return self._list(request, params, contents, page_name)
- def _getPickData(self, model, filter, logic):
+ def _getData(self, model, filter, order, logic):
"""Retrieves the pick data for this query.
Args:
@@ -662,7 +662,7 @@
logic: the logic that will be used for the query
"""
- entities = logic.getForFields(filter=filter, limit=1000)
+ entities = logic.getForFields(filter=filter, order=order, limit=1000)
return entities
@decorators.merge_params
@@ -693,11 +693,12 @@
filter[key] = request.GET.getlist(key)
if params['cache_pick']:
- fun = soc.cache.logic.cache(self._getPickData)
+ fun = soc.cache.logic.cache(self._getData)
else:
- fun = self._getPickData
+ fun = self._getData
- entities = fun(logic._model, filter, logic)
+ order = []
+ entities = fun(logic.getModel(), filter, order, logic)
data = [i.toDict() for i in entities]