I put your view on our production. I found that the query was causing action trigger cron jobs to dog pile. The query was too slow. To fix it in the immediate, I editing the query to only return balance_owed > 0
CREATE OR REPLACE VIEW money.usr_summary_per_org_unit AS
WITH located_xact AS (
SELECT circulation.id, circulation.circ_lib AS billing_ou
FROM action.circulation
UNION
SELECT grocery.id, grocery.billing_location AS billing_ou
FROM money.grocery
)
SELECT mmbts.usr,
located_xact.billing_ou,
sum(mmbts.total_paid) AS total_paid,
sum(mmbts.total_owed) AS total_owed,
sum(mmbts.balance_owed) AS balance_owed,
COALESCE(max(mmbts.last_payment_ts), '0001-01-01 00:00:00'::timestamp without time zone::timestamp with time zone) AS last_payment_ts
FROM money.materialized_billable_xact_summary mmbts
JOIN located_xact ON located_xact.id = mmbts.id
WHERE mmbts.balance_owed > 0::numeric
GROUP BY mmbts.usr, located_xact.billing_ou;
It also cut back on the number of "invalid" action_trigger.event rows.
Of course, it's not the solution unless we change the name of the view to reflect the filter.
Remington,
I put your view on our production. I found that the query was causing action trigger cron jobs to dog pile. The query was too slow. To fix it in the immediate, I editing the query to only return balance_owed > 0
CREATE OR REPLACE VIEW money.usr_ summary_ per_org_ unit AS
circulatio n.circ_ lib AS billing_ou
grocery. billing_ location AS billing_ou xact.billing_ ou, mmbts.total_ paid) AS total_paid, mmbts.total_ owed) AS total_owed, mmbts.balance_ owed) AS balance_owed, max(mmbts. last_payment_ ts), '0001-01-01 00:00:00' ::timestamp without time zone::timestamp with time zone) AS last_payment_ts zed_billable_ xact_summary mmbts xact.billing_ ou;
WITH located_xact AS (
SELECT circulation.id,
FROM action.circulation
UNION
SELECT grocery.id,
FROM money.grocery
)
SELECT mmbts.usr,
located_
sum(
sum(
sum(
COALESCE(
FROM money.materiali
JOIN located_xact ON located_xact.id = mmbts.id
WHERE mmbts.balance_owed > 0::numeric
GROUP BY mmbts.usr, located_
It also cut back on the number of "invalid" action_ trigger. event rows.
Of course, it's not the solution unless we change the name of the view to reflect the filter.