Update purge hook for non-template updates
authorMagnus Hagander <magnus@hagander.net>
Mon, 16 Jul 2018 09:31:21 +0000 (11:31 +0200)
committerMagnus Hagander <magnus@hagander.net>
Mon, 16 Jul 2018 09:31:21 +0000 (11:31 +0200)
For /media/ changes, generate a classic purge based on the URL. For
anything tha'ts not templates *or* media, just don't generate any purges
at all (of course).

tools/purgehook/purgehook.py

index aedfbb31d425ebc01311926ce43ca26e1ecb59b6..36d259f3c9d21591224566eab345761cb34b1bf2 100755 (executable)
@@ -24,10 +24,17 @@ if __name__ == "__main__":
        curs = conn.cursor()
 
        for l in sys.stdin:
-               tmpl = l[len('templates/'):].strip()
-               if not tmpl in BANNED_TEMPLATES:
-                       curs.execute("SELECT varnish_purge_xkey(%(key)s)", {
-                               'key': 'pgwt_{0}'.format(hashlib.md5(tmpl).hexdigest()),
+               if l.startswith('templates/'):
+                       tmpl = l[len('templates/'):].strip()
+                       if not tmpl in BANNED_TEMPLATES:
+                               curs.execute("SELECT varnish_purge_xkey(%(key)s)", {
+                                       'key': 'pgwt_{0}'.format(hashlib.md5(tmpl).hexdigest()),
+                               })
+               elif l.startswith('media/'):
+                       # For media we can't xkey, but the URL is exact so we can
+                       # use a classic single-url purge.
+                       curs.execute("SELECT varnish_purge('^/' || %(u)s || '$')", {
+                               'u': l.strip(),
                        })
        conn.commit()
        conn.close()