Skip to content

Commit 23de75b

Browse files
ewdurbinJacobCoffee
authored andcommitted
purge sitetree cache on change
- matches our caching between dev/prod - adds signal to purge sitetree caches on change Note: we _should_ migrate to redis for caching, it wasn't around when we first added it
1 parent 2d9ec09 commit 23de75b

5 files changed

Lines changed: 129 additions & 2 deletions

File tree

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ help: ## Display this help text
1616
mkdir -p .state && touch .state/db-migrated
1717

1818
.state/db-initialized: .state/docker-build-web .state/db-migrated
19+
docker compose run --rm web ./manage.py createcachetable
1920
docker compose run --rm web ./manage.py loaddata fixtures/*.json
2021
mkdir -p .state && touch .state/db-initialized
2122

pydotorg/apps.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from django.apps import AppConfig
2+
3+
4+
class PyDotOrgConfig(AppConfig):
5+
name = "pydotorg"
6+
7+
def ready(self):
8+
import pydotorg.signals # noqa: F401

pydotorg/settings/base.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@
171171
### Apps
172172

173173
INSTALLED_APPS = [
174+
<<<<<<< HEAD
174175
"django.contrib.auth",
175176
"django.contrib.contenttypes",
176177
"django.contrib.sessions",
@@ -195,6 +196,7 @@
195196
"widget_tweaks",
196197
"django_countries",
197198
"sorl.thumbnail",
199+
"pydotorg",
198200
"apps.banners",
199201
"apps.blogs",
200202
"apps.boxes",
@@ -215,6 +217,108 @@
215217
"apps.work_groups",
216218
"allauth",
217219
"allauth.account",
220+
||||||| parent of ac1d365e (purge sitetree cache on change)
221+
'django.contrib.auth',
222+
'django.contrib.contenttypes',
223+
'django.contrib.sessions',
224+
'django.contrib.sites',
225+
'django.contrib.redirects',
226+
'django.contrib.messages',
227+
'django.contrib.staticfiles',
228+
'django.contrib.humanize',
229+
230+
'admin_interface',
231+
'colorfield',
232+
'django.contrib.admin',
233+
'django.contrib.admindocs',
234+
235+
'django_celery_beat',
236+
'django_translation_aliases',
237+
'pipeline',
238+
'sitetree',
239+
'imagekit',
240+
'haystack',
241+
'honeypot',
242+
'waffle',
243+
'ordered_model',
244+
'widget_tweaks',
245+
'django_countries',
246+
'sorl.thumbnail',
247+
248+
'banners',
249+
'blogs',
250+
'boxes',
251+
'cms',
252+
'codesamples',
253+
'community',
254+
'companies',
255+
'downloads',
256+
'events',
257+
'jobs',
258+
'mailing',
259+
'minutes',
260+
'nominations',
261+
'pages',
262+
'sponsors',
263+
'successstories',
264+
'users',
265+
'work_groups',
266+
267+
'allauth',
268+
'allauth.account',
269+
270+
=======
271+
'django.contrib.auth',
272+
'django.contrib.contenttypes',
273+
'django.contrib.sessions',
274+
'django.contrib.sites',
275+
'django.contrib.redirects',
276+
'django.contrib.messages',
277+
'django.contrib.staticfiles',
278+
'django.contrib.humanize',
279+
280+
'admin_interface',
281+
'colorfield',
282+
'django.contrib.admin',
283+
'django.contrib.admindocs',
284+
285+
'django_celery_beat',
286+
'django_translation_aliases',
287+
'pipeline',
288+
'sitetree',
289+
'imagekit',
290+
'haystack',
291+
'honeypot',
292+
'waffle',
293+
'ordered_model',
294+
'widget_tweaks',
295+
'django_countries',
296+
'sorl.thumbnail',
297+
298+
'pydotorg',
299+
'banners',
300+
'blogs',
301+
'boxes',
302+
'cms',
303+
'codesamples',
304+
'community',
305+
'companies',
306+
'downloads',
307+
'events',
308+
'jobs',
309+
'mailing',
310+
'minutes',
311+
'nominations',
312+
'pages',
313+
'sponsors',
314+
'successstories',
315+
'users',
316+
'work_groups',
317+
318+
'allauth',
319+
'allauth.account',
320+
321+
>>>>>>> ac1d365e (purge sitetree cache on change)
218322
# Tastypie needs the `users` app to be already loaded.
219323
"tastypie",
220324
"rest_framework",

pydotorg/settings/local.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141

4242
CACHES = {
4343
"default": {
44-
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
45-
"LOCATION": "pythondotorg-local-cache",
44+
"BACKEND": "django.core.cache.backends.db.DatabaseCache",
45+
"LOCATION": "django_cache_table",
4646
}
4747
}
4848

pydotorg/signals.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from django.db.models.signals import m2m_changed, post_delete, post_save
2+
from django.dispatch import receiver
3+
4+
from sitetree.models import Tree, TreeItem
5+
from sitetree.sitetreeapp import get_sitetree
6+
7+
@receiver(post_save, sender=Tree)
8+
@receiver(post_save, sender=TreeItem)
9+
@receiver(post_delete, sender=TreeItem)
10+
@receiver(m2m_changed, sender=TreeItem.access_permissions)
11+
def purge_sitetree_cache(sender, instance, **kwargs):
12+
cache_ = get_sitetree().cache
13+
cache_.empty()
14+
cache_.reset()

0 commit comments

Comments
 (0)