Make documentation purges use xkey
authorMagnus Hagander <magnus@hagander.net>
Tue, 18 May 2021 07:39:23 +0000 (09:39 +0200)
committerMagnus Hagander <magnus@hagander.net>
Tue, 18 May 2021 07:54:18 +0000 (09:54 +0200)
docs/frontend.rst
pgweb/core/models.py
pgweb/util/signals.py
tools/docs/docload.py

index 813d399f29dc4f905b7c087c0fbf01273acf4b97..2cde54d48486b5510f44a790024aa04fe2cb88d3 100644 (file)
@@ -56,6 +56,10 @@ purge "/" since that will remove everything from the cache completely).
 This makes it possible to have frontends react instantly to changes,
 while maintaining high cacheability.
 
+Any model can also define a tuple or function called *purge_xkeys*.
+This work exactly the same way except it purges based on xkey instead
+of URL, which is usually the better choice.
+
 Finally, there is a form on the admin web interface that lets the
 administrator manually purge pages from the caches. This may be
 necessary if changes have been made to static pages and/or site
index ec52ab59515bd1df48559f14327b361ce997d494..f912c68b48b2fdd883102649ca11bc8bd539c233 100644 (file)
@@ -79,12 +79,13 @@ class Version(models.Model):
         yield '/$'
         yield '/support/versioning'
         yield '/support/security'
-        yield '/docs/$'
-        yield '/docs/manuals'
         yield '/about/featurematrix/$'
         yield '/versions.rss'
         yield '/versions.json'
 
+    def purge_xkeys(self):
+        yield 'pgdocs_all'
+
 
 class Country(models.Model):
     name = models.CharField(max_length=100, null=False, blank=False)
index d555a83b1a237d1a5380df80a37c27935ec5eeef..0552ea33526b285bef3e4f4eeb6dee15b234b50d 100644 (file)
@@ -5,7 +5,7 @@ from django.conf import settings
 import difflib
 
 from pgweb.util.middleware import get_current_user
-from pgweb.util.misc import varnish_purge
+from pgweb.util.misc import varnish_purge, varnish_purge_xkey
 from pgweb.util.moderation import ModerationState
 from pgweb.mailqueue.util import send_simple_mail
 
@@ -157,6 +157,12 @@ def my_post_save_handler(sender, **kwargs):
         else:
             purgelist = instance.purge_urls
         list(map(varnish_purge, purgelist))
+    if hasattr(instance, 'purge_xkeys'):
+        if callable(instance.purge_xkeys):
+            purgelist = instance.purge_xkeys()
+        else:
+            purgelist = instance.purge_xkeys
+        list(map(varnish_purge_xkey, purgelist))
 
 
 def register_basic_signal_handlers():
index 49e323a976c85817e1e8fec189a72984e94d5f48..427a93458cf7b79142db98e7b26cedd9d2938d38 100755 (executable)
@@ -227,9 +227,10 @@ if numchanges > 0:
         # Special handling of developer docs...
         ver = "devel"
 
-    curs.execute("SELECT varnish_purge('^/docs/' || %(v)s || '/')", {'v': ver})
+    curs.execute("SELECT varnish_purge_xkey('pgdocs_{}')".format(ver))
+    curs.execute("SELECT varnish_purge_xkey('pgdocs_all')")
     if iscurrent:
-        curs.execute("SELECT varnish_purge('^/docs/current/')")
+        curs.execute("SELECT varnish_purge_xkey('pgdocs_current')")
 
 # ensure the changes are committed, and close the connection
 connection.commit()