Handle varnish purges for the static repo as well
authorMagnus Hagander <magnus@hagander.net>
Mon, 17 May 2021 10:03:35 +0000 (12:03 +0200)
committerMagnus Hagander <magnus@hagander.net>
Mon, 17 May 2021 10:03:35 +0000 (12:03 +0200)
By calling the purge notifier script with --static, the paths wil be
taken as part of the pgweb-static repostory instead, and purged with a
prefix of files/

tools/purgehook/purgehook.py

index 3f064028147c96a5062cf67fad38a05ba9065bc1..fed909d19f8801e9daed80e08968b8fd1b4a5948 100755 (executable)
@@ -24,7 +24,13 @@ if __name__ == "__main__":
     curs = conn.cursor()
 
     for l in sys.stdin:
-        if l.startswith('templates/'):
+        if '--static' in sys.argv:
+            # For the static files part, we always purge just on filename, with a prefix
+            curs.execute("SELECT varnish_purge('^/files/' || %(u)s || '$')", {
+                'u': l.strip(),
+            })
+        elif l.startswith('templates/'):
+            # On regular website, if it's a template do an xkey purge of all pages using that template
             tmpl = l[len('templates/'):].strip()
             if tmpl not in BANNED_TEMPLATES:
                 curs.execute("SELECT varnish_purge_xkey(%(key)s)", {