X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=priv%2Frepo%2Fmigrations%2F20200508092434_update_counter_cache_table.exs;h=73834486851d1dac6d6eaf5fea95c298ff5631fd;hb=ccdf55acff7ff7d29682aab3ccf283b59ad33d26;hp=81a8d6397d34b2c15e5cb7025dc311c461ee0890;hpb=0c2b09a9ba771b3b04a0a08ed940823bd8601a9f;p=akkoma diff --git a/priv/repo/migrations/20200508092434_update_counter_cache_table.exs b/priv/repo/migrations/20200508092434_update_counter_cache_table.exs index 81a8d6397..738344868 100644 --- a/priv/repo/migrations/20200508092434_update_counter_cache_table.exs +++ b/priv/repo/migrations/20200508092434_update_counter_cache_table.exs @@ -25,25 +25,21 @@ defmodule Pleroma.Repo.Migrations.UpdateCounterCacheTable do RETURNS TRIGGER AS $$ DECLARE - token_id smallint; hostname character varying(255); visibility_new character varying(64); visibility_old character varying(64); actor character varying(255); BEGIN - SELECT "tokid" INTO "token_id" FROM ts_token_type('default') WHERE "alias" = 'host'; IF TG_OP = 'DELETE' THEN actor := OLD.actor; ELSE actor := NEW.actor; END IF; - SELECT "token" INTO "hostname" FROM ts_parse('default', actor) WHERE "tokid" = token_id; - IF hostname IS NULL THEN - hostname := split_part(actor, '/', 3); - END IF; + hostname := split_part(actor, '/', 3); IF TG_OP = 'INSERT' THEN visibility_new := activity_visibility(NEW.actor, NEW.recipients, NEW.data); - IF NEW.data->>'type' = 'Create' THEN + IF NEW.data->>'type' = 'Create' + AND visibility_new IN ('public', 'unlisted', 'private', 'direct') THEN EXECUTE format('INSERT INTO "counter_cache" ("instance", %1$I) VALUES ($1, 1) ON CONFLICT ("instance") DO UPDATE SET %1$I = "counter_cache".%1$I + 1', visibility_new) @@ -53,7 +49,10 @@ defmodule Pleroma.Repo.Migrations.UpdateCounterCacheTable do ELSIF TG_OP = 'UPDATE' THEN visibility_new := activity_visibility(NEW.actor, NEW.recipients, NEW.data); visibility_old := activity_visibility(OLD.actor, OLD.recipients, OLD.data); - IF (NEW.data->>'type' = 'Create') and (OLD.data->>'type' = 'Create') and visibility_new != visibility_old THEN + IF (NEW.data->>'type' = 'Create') + AND (OLD.data->>'type' = 'Create') + AND visibility_new != visibility_old + AND visibility_new IN ('public', 'unlisted', 'private', 'direct') THEN EXECUTE format('UPDATE "counter_cache" SET %1$I = greatest("counter_cache".%1$I - 1, 0), %2$I = "counter_cache".%2$I + 1