diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2012-11-14 22:44:27 -0500 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2012-11-14 22:44:27 -0500 |
commit | 64f6dd9cb41ddbc84376549f558ed7d52d9e600a (patch) | |
tree | 81f31f1ceb5fc6e4d94508d273003996e036191c /main | |
parent | bc432a1ff0e69bf45c5f3b97077a13952611196d (diff) | |
parent | b2b5c1a064d5d3c33f4c4fc119bd67cf9ca1b7ba (diff) |
Merge tag 'release_2012-01-11'
Pkgbase view in todos, other changes related to caching
Conflicts:
public/views.py
Diffstat (limited to 'main')
-rw-r--r-- | main/middleware.py | 52 | ||||
-rw-r--r-- | main/models.py | 14 |
2 files changed, 6 insertions, 60 deletions
diff --git a/main/middleware.py b/main/middleware.py deleted file mode 100644 index f417b545..00000000 --- a/main/middleware.py +++ /dev/null @@ -1,52 +0,0 @@ -# begin copy of stock Django UpdateCacheMiddleware -# this is to address feeds caching issue which makes it horribly -# unperformant - -from django.conf import settings -from django.core.cache import cache -from django.utils.cache import learn_cache_key, patch_response_headers, get_max_age - -class UpdateCacheMiddleware(object): - """ - Response-phase cache middleware that updates the cache if the response is - cacheable. - - Must be used as part of the two-part update/fetch cache middleware. - UpdateCacheMiddleware must be the first piece of middleware in - MIDDLEWARE_CLASSES so that it'll get called last during the response phase. - """ - def __init__(self): - self.cache_timeout = settings.CACHE_MIDDLEWARE_SECONDS - self.key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX - self.cache_anonymous_only = getattr(settings, 'CACHE_MIDDLEWARE_ANONYMOUS_ONLY', False) - - def process_response(self, request, response): - """Sets the cache, if needed.""" - if not hasattr(request, '_cache_update_cache') or not request._cache_update_cache: - # We don't need to update the cache, just return. - return response - if request.method != 'GET': - # This is a stronger requirement than above. It is needed - # because of interactions between this middleware and the - # HTTPMiddleware, which throws the body of a HEAD-request - # away before this middleware gets a chance to cache it. - return response - if not response.status_code == 200: - return response - # Try to get the timeout from the "max-age" section of the "Cache- - # Control" header before reverting to using the default cache_timeout - # length. - timeout = get_max_age(response) - if timeout == None: - timeout = self.cache_timeout - elif timeout == 0: - # max-age was set to 0, don't bother caching. - return response - patch_response_headers(response, timeout) - if timeout: - response.content = response.content - cache_key = learn_cache_key(request, response, timeout, self.key_prefix) - cache.set(cache_key, response, timeout) - return response - -# vim: set ts=4 sw=4 et: diff --git a/main/models.py b/main/models.py index cefebf76..d72f2c05 100644 --- a/main/models.py +++ b/main/models.py @@ -1,8 +1,6 @@ from django.db import models -from django.db.models.signals import pre_save from django.contrib.auth.models import User from django.contrib.sites.models import Site -from django.forms import ValidationError from .fields import PositiveBigIntegerField, PGPKeyField from .utils import cache_function, make_choice, set_created_field @@ -203,14 +201,14 @@ class Package(models.Model): def maintainers(self, maintainers): self._maintainers = maintainers - @cache_function(300) + @cache_function(1800) def applicable_arches(self): '''The list of (this arch) + (available agnostic arches).''' arches = set(Arch.objects.filter(agnostic=True)) arches.add(self.arch) return list(arches) - @cache_function(300) + @cache_function(119) def get_requiredby(self): """ Returns a list of package objects. An attempt will be made to keep this @@ -229,7 +227,7 @@ class Package(models.Model): pkg__arch__in=self.applicable_arches()) # sort out duplicate packages; this happens if something has a double # versioned dep such as a kernel module - requiredby = [list(vals)[0] for k, vals in + requiredby = [list(vals)[0] for _, vals in groupby(requiredby, lambda x: x.pkg.id)] # find another package by this name in the opposite testing setup @@ -244,7 +242,7 @@ class Package(models.Model): # for each unique package name, try to screen our package list down to # those packages in the same testing category (yes or no) iff there is # a package in the same testing category. - for name, dep_pkgs in groupby(requiredby, lambda x: x.pkg.pkgname): + for _, dep_pkgs in groupby(requiredby, lambda x: x.pkg.pkgname): dep_pkgs = list(dep_pkgs) dep = dep_pkgs[0] if len(dep_pkgs) > 1: @@ -256,7 +254,7 @@ class Package(models.Model): trimmed.append(dep) return trimmed - @cache_function(300) + @cache_function(121) def get_depends(self): """ Returns a list of dicts. Each dict contains ('dep', 'pkg', and @@ -281,7 +279,7 @@ class Package(models.Model): deps.append({'dep': dep, 'pkg': pkg, 'providers': providers}) return deps - @cache_function(300) + @cache_function(125) def base_package(self): """ Locate the base package for this package. It may be this very package, |