Do not call CDB_Invalidate_Varnish() if not owned by a superuser
Search for that function in schemas cartodb and public (in that order). Closes #24
This commit is contained in:
parent
ca4ce102bb
commit
2f0031e6a2
@ -1,15 +1,4 @@
|
||||
\set VERBOSITY terse
|
||||
-- Create a stub cdb_invalidate_varnish function if not available
|
||||
--CREATE FUNCTION tmp() returns void AS $$
|
||||
DO $$
|
||||
BEGIN
|
||||
PERFORM cdb_invalidate_varnish(0);
|
||||
EXCEPTION
|
||||
WHEN undefined_function THEN
|
||||
CREATE OR REPLACE FUNCTION cartodb.cdb_invalidate_varnish(tabname text)
|
||||
RETURNS void AS '' LANGUAGE 'sql';
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
-- Set user quota to infinite
|
||||
SELECT CDB_SetUserQuotaInBytes(0);
|
||||
cdb_setuserquotainbytes
|
||||
|
@ -62,6 +62,8 @@ RETURNS trigger AS
|
||||
$$
|
||||
DECLARE
|
||||
tabname TEXT;
|
||||
rec RECORD;
|
||||
found BOOL;
|
||||
BEGIN
|
||||
|
||||
IF TG_OP = 'UPDATE' or TG_OP = 'INSERT' THEN
|
||||
@ -82,11 +84,27 @@ BEGIN
|
||||
--
|
||||
-- LISTEN cdb_tabledata_update;
|
||||
--
|
||||
BEGIN
|
||||
PERFORM cdb_invalidate_varnish(tabname);
|
||||
EXCEPTION WHEN undefined_function THEN
|
||||
RAISE WARNING 'Missing cdb_invalidate_varnish()';
|
||||
END;
|
||||
|
||||
-- Call the first varnish invalidation function owned
|
||||
-- by a superuser found in cartodb or public schema
|
||||
-- (in that order)
|
||||
found := false;
|
||||
FOR rec IN SELECT u.usesuper, u.usename, n.nspname, p.proname
|
||||
FROM pg_proc p, pg_namespace n, pg_user u
|
||||
WHERE p.proname = 'cdb_invalidate_varnish'
|
||||
AND p.pronamespace = n.oid
|
||||
AND n.nspname IN ('public', 'cartodb')
|
||||
AND u.usesysid = p.proowner
|
||||
AND u.usesuper
|
||||
ORDER BY n.nspname
|
||||
LOOP
|
||||
EXECUTE 'SELECT ' || quote_ident(rec.nspname) || '.'
|
||||
|| quote_ident(rec.proname)
|
||||
|| '(' || quote_literal(tabname) || ')';
|
||||
found := true;
|
||||
EXIT;
|
||||
END LOOP;
|
||||
IF NOT found THEN RAISE WARNING 'Missing cdb_invalidate_varnish()'; END IF;
|
||||
|
||||
RETURN NULL;
|
||||
END;
|
||||
|
@ -1,17 +1,5 @@
|
||||
\set VERBOSITY terse
|
||||
|
||||
-- Create a stub cdb_invalidate_varnish function if not available
|
||||
--CREATE FUNCTION tmp() returns void AS $$
|
||||
DO $$
|
||||
BEGIN
|
||||
PERFORM cdb_invalidate_varnish(0);
|
||||
EXCEPTION
|
||||
WHEN undefined_function THEN
|
||||
CREATE OR REPLACE FUNCTION cartodb.cdb_invalidate_varnish(tabname text)
|
||||
RETURNS void AS '' LANGUAGE 'sql';
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql';
|
||||
|
||||
-- Set user quota to infinite
|
||||
SELECT CDB_SetUserQuotaInBytes(0);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user