cache max_bounds
This commit is contained in:
parent
03e35a019e
commit
9bfa48ba2c
2 changed files with 11 additions and 3 deletions
|
@ -1,8 +1,8 @@
|
|||
from c3nav.mapdata.models.update import MapUpdate # noqa
|
||||
from c3nav.mapdata.models.access import AccessRestriction # noqa
|
||||
from c3nav.mapdata.models.level import Level # noqa
|
||||
from c3nav.mapdata.models.geometry.level import Building, Space, Door, AltitudeArea # noqa
|
||||
from c3nav.mapdata.models.geometry.space import Area, Stair, Obstacle, LineObstacle, Hole, AltitudeMarker # noqa
|
||||
from c3nav.mapdata.models.locations import Location, LocationSlug, LocationGroup, LocationGroupCategory # noqa
|
||||
from c3nav.mapdata.models.source import Source # noqa
|
||||
from c3nav.mapdata.models.update import MapUpdate # noqa
|
||||
from c3nav.mapdata.models.graph import GraphNode, WayType, GraphEdge # noqa
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
from collections import OrderedDict
|
||||
|
||||
from django.core.cache import cache
|
||||
from django.db import models
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import get_language
|
||||
|
||||
from c3nav.mapdata.fields import JSONField
|
||||
from c3nav.mapdata.models import MapUpdate
|
||||
|
||||
|
||||
class SerializableMixin(models.Model):
|
||||
|
@ -78,10 +80,16 @@ class BoundsMixin(SerializableMixin, models.Model):
|
|||
|
||||
@classmethod
|
||||
def max_bounds(cls):
|
||||
cache_key = 'mapdata:max_bounds:%s:%s' % (cls.__name__, MapUpdate.cache_key())
|
||||
result = cache.get(cache_key, None)
|
||||
if result is not None:
|
||||
return result
|
||||
result = cls.objects.all().aggregate(models.Min('bottom'), models.Min('left'),
|
||||
models.Max('top'), models.Max('right'))
|
||||
return ((float(result['bottom__min']), float(result['left__min'])),
|
||||
(float(result['top__max']), float(result['right__max'])))
|
||||
result = ((float(result['bottom__min']), float(result['left__min'])),
|
||||
(float(result['top__max']), float(result['right__max'])))
|
||||
cache.set(cache_key, result, 900)
|
||||
return result
|
||||
|
||||
def _serialize(self, level=True, **kwargs):
|
||||
result = super()._serialize(**kwargs)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue