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:
@@ -1,15 +1,4 @@
|
|||||||
\set VERBOSITY terse
|
\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
|
-- Set user quota to infinite
|
||||||
SELECT CDB_SetUserQuotaInBytes(0);
|
SELECT CDB_SetUserQuotaInBytes(0);
|
||||||
cdb_setuserquotainbytes
|
cdb_setuserquotainbytes
|
||||||
|
|||||||
@@ -62,6 +62,8 @@ RETURNS trigger AS
|
|||||||
$$
|
$$
|
||||||
DECLARE
|
DECLARE
|
||||||
tabname TEXT;
|
tabname TEXT;
|
||||||
|
rec RECORD;
|
||||||
|
found BOOL;
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
||||||
IF TG_OP = 'UPDATE' or TG_OP = 'INSERT' THEN
|
IF TG_OP = 'UPDATE' or TG_OP = 'INSERT' THEN
|
||||||
@@ -82,11 +84,27 @@ BEGIN
|
|||||||
--
|
--
|
||||||
-- LISTEN cdb_tabledata_update;
|
-- LISTEN cdb_tabledata_update;
|
||||||
--
|
--
|
||||||
BEGIN
|
|
||||||
PERFORM cdb_invalidate_varnish(tabname);
|
-- Call the first varnish invalidation function owned
|
||||||
EXCEPTION WHEN undefined_function THEN
|
-- by a superuser found in cartodb or public schema
|
||||||
RAISE WARNING 'Missing cdb_invalidate_varnish()';
|
-- (in that order)
|
||||||
END;
|
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;
|
RETURN NULL;
|
||||||
END;
|
END;
|
||||||
|
|||||||
@@ -1,17 +1,5 @@
|
|||||||
\set VERBOSITY terse
|
\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
|
-- Set user quota to infinite
|
||||||
SELECT CDB_SetUserQuotaInBytes(0);
|
SELECT CDB_SetUserQuotaInBytes(0);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user