# HG changeset patch # User Sverre Rabbelier # Date 1236806928 0 # Node ID 5cd78a7aacdd674e897d4b286f0b8311f556d0ea # Parent 336c35c82b875b0f23fb7123658063a96a89c9f9 Allow for query caching in pick Turn the caching on for /user/pick Patch by: Sverre Rabbelier diff -r 336c35c82b87 -r 5cd78a7aacdd app/soc/views/helper/params.py --- a/app/soc/views/helper/params.py Wed Mar 11 21:28:11 2009 +0000 +++ b/app/soc/views/helper/params.py Wed Mar 11 21:28:48 2009 +0000 @@ -229,6 +229,8 @@ new_params['context'] = None + new_params['cache_pick'] = False + new_params['export_content_type'] = None new_params['export_extension'] = '.txt' diff -r 336c35c82b87 -r 5cd78a7aacdd app/soc/views/models/base.py --- a/app/soc/views/models/base.py Wed Mar 11 21:28:11 2009 +0000 +++ b/app/soc/views/models/base.py Wed Mar 11 21:28:48 2009 +0000 @@ -38,6 +38,7 @@ from soc.views.helper import responses from soc.views import sitemap +import soc.cache.logic import soc.logic import soc.logic.lists import soc.views.helper.lists @@ -615,6 +616,19 @@ return self._list(request, params, contents, page_name) + def _getPickData(self, model, filter, logic): + """Retrieves the pick data for this query. + + Args: + model: the model that is being queried + filter: the filters that apply + logic: the logic that will be used for the query + """ + + query = logic.getQueryForFields(filter=filter) + entities = logic.getAll(query) + return entities + @decorators.merge_params @decorators.check_access def pick(self, request, acces_type, page_name=None, params=None): @@ -642,8 +656,12 @@ # need to use getlist as we want to support multiple values filter[key] = request.GET.getlist(key) - query = logic.getQueryForFields(filter=filter) - entities = logic.getAll(query) + if params['cache_pick']: + fun = soc.cache.logic.cache(self._getPickData) + else: + fun = self._getPickData + + entities = fun(logic._model, filter, logic) data = [i.toDict() for i in entities] diff -r 336c35c82b87 -r 5cd78a7aacdd app/soc/views/models/user.py --- a/app/soc/views/models/user.py Wed Mar 11 21:28:11 2009 +0000 +++ b/app/soc/views/models/user.py Wed Mar 11 21:28:48 2009 +0000 @@ -71,6 +71,7 @@ new_params['edit_template'] = 'soc/user/edit.html' new_params['pickable'] = True + new_params['cache_pick'] = True new_params['sidebar_heading'] = 'Users'