mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-05 08:32:02 +00:00
remove performance-problematic and buggy duplicate site aggregates (#3732)
This commit is contained in:
parent
d909f3455d
commit
1253a2a0d5
2 changed files with 26 additions and 0 deletions
11
migrations/2023-07-26-222023_site-aggregates-one/down.sql
Normal file
11
migrations/2023-07-26-222023_site-aggregates-one/down.sql
Normal file
|
@ -0,0 +1,11 @@
|
|||
create or replace function site_aggregates_site()
|
||||
returns trigger language plpgsql
|
||||
as $$
|
||||
begin
|
||||
IF (TG_OP = 'INSERT') THEN
|
||||
insert into site_aggregates (site_id) values (NEW.id);
|
||||
ELSIF (TG_OP = 'DELETE') THEN
|
||||
delete from site_aggregates where site_id = OLD.id;
|
||||
END IF;
|
||||
return null;
|
||||
end $$;
|
15
migrations/2023-07-26-222023_site-aggregates-one/up.sql
Normal file
15
migrations/2023-07-26-222023_site-aggregates-one/up.sql
Normal file
|
@ -0,0 +1,15 @@
|
|||
create or replace function site_aggregates_site()
|
||||
returns trigger language plpgsql
|
||||
as $$
|
||||
begin
|
||||
-- we only ever want to have a single value in site_aggregate because the site_aggregate triggers update all rows in that table.
|
||||
-- a cleaner check would be to insert it for the local_site but that would break assumptions at least in the tests
|
||||
IF (TG_OP = 'INSERT') AND NOT EXISTS (select id from site_aggregates limit 1) THEN
|
||||
insert into site_aggregates (site_id) values (NEW.id);
|
||||
ELSIF (TG_OP = 'DELETE') THEN
|
||||
delete from site_aggregates where site_id = OLD.id;
|
||||
END IF;
|
||||
return null;
|
||||
end $$;
|
||||
|
||||
delete from site_aggregates a where not exists (select id from local_site s where s.site_id = a.site_id);
|
Loading…
Reference in a new issue