Skip to content

Commit

Permalink
Merge 044f066 into 2e66206
Browse files Browse the repository at this point in the history
  • Loading branch information
submarcos authored Dec 1, 2022
2 parents 2e66206 + 044f066 commit c2805b1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.92.1
2.92.1+dev
4 changes: 4 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ CHANGELOG
2.92.1+dev (XXXX-XX-XX)
-----------------------

**Bug fixes**

- Fix cache management in API v2


2.92.1 (2022-12-01)
-----------------------
Expand Down
5 changes: 4 additions & 1 deletion geotrek/api/v2/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from mapentity.renderers import GeoJSONRenderer
from rest_framework import viewsets, renderers
from rest_framework.authentication import BasicAuthentication, SessionAuthentication
from rest_framework.generics import get_object_or_404
from rest_framework.permissions import IsAuthenticatedOrReadOnly, IsAuthenticated

from geotrek.api.v2 import pagination as api_pagination, filters as api_filters
Expand Down Expand Up @@ -37,7 +38,9 @@ def get_base_cache_string(self):
def get_object_cache_key(self, pk):
""" return specific object cache key based on object date_update column"""
# don't directly use get_object or get_queryset to avoid select / prefetch and annotation sql queries
date_update = self.get_queryset().model.objects.get(pk=pk).date_update
# insure object exists and doesn't raise exception
instance = get_object_or_404(self.get_queryset().model, pk=pk)
date_update = instance.date_update
return f"{self.get_base_cache_string()}:{date_update.isoformat()}"

def object_cache_key_func(self, **kwargs):
Expand Down
1 change: 1 addition & 0 deletions geotrek/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,7 @@ def api_bbox(bbox, buffer):
LEAFLET_CONFIG['SPATIAL_EXTENT'] = api_bbox(SPATIAL_EXTENT, VIEWPORT_MARGIN)

REST_FRAMEWORK_EXTENSIONS = {
'DEFAULT_USE_CACHE': 'api_v2',
'DEFAULT_CACHE_ERRORS': False
}

Expand Down

0 comments on commit c2805b1

Please sign in to comment.