From 4ea3c2c920353289516abc3fa345af624fdff238 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Thu, 15 Nov 2018 11:49:03 +0100 Subject: [PATCH] wcs: add db cache refresh to formdef/category cells (#28043) --- combo/apps/wcs/__init__.py | 10 ++++++++++ tests/test_wcs.py | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/combo/apps/wcs/__init__.py b/combo/apps/wcs/__init__.py index 1d3ae8f4..f60952ae 100644 --- a/combo/apps/wcs/__init__.py +++ b/combo/apps/wcs/__init__.py @@ -34,4 +34,14 @@ class AppConfig(django.apps.AppConfig): from . import urls return urls.urlpatterns + def hourly(self): + self.update_db_cache() + + def update_db_cache(self): + from combo.data.models import CellBase + from .models import WcsFormCell, WcsCategoryCell, WcsFormsOfCategoryCell + for cell in CellBase.get_cells( + cell_filter=lambda x: x in (WcsFormCell, WcsCategoryCell, WcsFormsOfCategoryCell)): + cell.save() + default_app_config = 'combo.apps.wcs.AppConfig' diff --git a/tests/test_wcs.py b/tests/test_wcs.py index c172cdd8..ca5f9a06 100644 --- a/tests/test_wcs.py +++ b/tests/test_wcs.py @@ -11,6 +11,7 @@ import tempfile import time import os +from django.apps import apps from django.conf import settings from django.core.cache import cache from django.test import override_settings @@ -267,6 +268,13 @@ def test_form_cell_save_cache(): 'url': 'http://127.0.0.1:8999/form-title/', 'text': ''}] + # artificially change title + WcsFormCell.objects.filter(id=cell.id).update(cached_title='XXX') + assert WcsFormCell.objects.get(id=cell.id).cached_title == 'XXX' + # run update db cache + appconfig = apps.get_app_config('wcs') + appconfig.update_db_cache() + assert WcsFormCell.objects.get(id=cell.id).cached_title == 'form title' @wcsctl_present def test_form_cell_load(): -- 2.19.1