divio/django-cms — pull request #1319 by piquadrat (2012-06-22 08:53:18+00:00)
Title: cache the result of the global page permission query on the request object

Currently, the following query is issued for every page in the page tree:

GlobalPagePermission.objects.with_user(request.user).filter(can_add=True, sites__in=[page.site_id]))

Since the result of the query should be the same during the rendering of the page tree, this can be cached, leading to a reduction of 1 query per page in the tree (so, if the tree as 100 pages, this query will be executed once instead of 100 times).

I'm not exactly happy with storing the cache dict on the ``request`` object. But storing the result in Django's cache would have drawbacks as well:

* we would replace the 100 db queries from the example above with 1 db query and 99 cache queries. Better, but still not ideal
* the cache is only valid during the life time of the request, so we would have to set a very short cache duration