fix cache invalidation / mapupdate creation in direct edit with DEBUG=False
This commit is contained in:
parent
de6e67d8ae
commit
3ee7cf91bf
4 changed files with 23 additions and 6 deletions
|
@ -0,0 +1 @@
|
|||
default_app_config = 'c3nav.editor.apps.EditorConfig'
|
12
src/c3nav/editor/apps.py
Normal file
12
src/c3nav/editor/apps.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
from django.apps import AppConfig
|
||||
from django.db.models.signals import m2m_changed, post_delete, post_save
|
||||
|
||||
|
||||
class EditorConfig(AppConfig):
|
||||
name = 'c3nav.editor'
|
||||
|
||||
def ready(self):
|
||||
from c3nav.editor.models import ChangeSet
|
||||
post_save.connect(ChangeSet.object_changed_handler)
|
||||
post_delete.connect(ChangeSet.object_changed_handler)
|
||||
m2m_changed.connect(ChangeSet.object_changed_handler)
|
|
@ -9,7 +9,7 @@ from django.apps import apps
|
|||
from django.conf import settings
|
||||
from django.core.cache import cache
|
||||
from django.core.exceptions import FieldDoesNotExist
|
||||
from django.db import connection, models, transaction
|
||||
from django.db import models, transaction
|
||||
from django.db.models import Q
|
||||
from django.urls import reverse
|
||||
from django.utils.http import int_to_base36
|
||||
|
@ -438,6 +438,13 @@ class ChangeSet(models.Model):
|
|||
def _cleaning_changes(self, value):
|
||||
self.cleaning_changes_cache[self.pk] = value
|
||||
|
||||
objects_changed_count = 0
|
||||
|
||||
@classmethod
|
||||
def object_changed_handler(cls, sender, instance, **kwargs):
|
||||
if sender._meta.app_label == 'mapdata':
|
||||
cls.objects_changed_count += 1
|
||||
|
||||
@contextmanager
|
||||
def lock_to_edit(self, request=None):
|
||||
with transaction.atomic():
|
||||
|
@ -455,10 +462,9 @@ class ChangeSet(models.Model):
|
|||
elif self.direct_editing:
|
||||
with MapUpdate.lock():
|
||||
changed_geometries.reset()
|
||||
queries_before = len(connection.queries)
|
||||
ChangeSet.objects_changed_count = 0
|
||||
yield self
|
||||
if any((q['sql'].startswith('UPDATE') or q['sql'].startswith('INSERT') or
|
||||
q['sql'].startswith('DELETE')) for q in connection.queries[queries_before:]):
|
||||
if ChangeSet.objects_changed_count:
|
||||
MapUpdate.objects.create(user=user, type='direct_edit')
|
||||
else:
|
||||
yield self
|
||||
|
|
|
@ -1,3 +1 @@
|
|||
|
||||
|
||||
default_app_config = 'c3nav.mapdata.apps.MapdataConfig'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue