~singpolyma/jmp-schemas

446d5d282fe8f94d4a476fca8e99949a3d0aa985 — Stephen Paul Weber 4 months ago ee7e7de 2022039.1
Fix for cdr_with_charge performance
A deploy/cdr_with_charge_faster.sql => deploy/cdr_with_charge_faster.sql +24 -0
@@ 0,0 1,24 @@
-- Deploy jmp:cdr_with_charge_faster to pg
-- requires: cdr_with_charge

BEGIN;

DROP VIEW cdr_with_charge;

CREATE VIEW cdr_with_charge AS
	SELECT DISTINCT ON (cdr_id, customer_id)
		cdr.*,
		rate,
		(CASE WHEN cdr.disposition = 'VOICEMAIL' THEN 0
		ELSE rate * ceiling(billsec / 60.0) END) AS charge
	FROM
		cdr
		INNER JOIN customer_plans USING (customer_id)
		LEFT JOIN call_rates ON
			cdr.direction = call_rates.direction AND
			customer_plans.plan_name = call_rates.plan_name AND
			cdr.tel LIKE call_rates.prefix || '%'
	ORDER BY cdr_id, customer_id, prefix DESC;


COMMIT;

A revert/cdr_with_charge_faster.sql => revert/cdr_with_charge_faster.sql +22 -0
@@ 0,0 1,22 @@
-- Revert jmp:cdr_with_charge_faster from pg

BEGIN;

DROP VIEW cdr_with_charge;

CREATE VIEW cdr_with_charge AS
	SELECT DISTINCT ON (cdr_id)
		cdr.*,
		rate,
		(CASE WHEN cdr.disposition = 'VOICEMAIL' THEN 0
		ELSE rate * ceiling(billsec / 60.0) END) AS charge
	FROM
		cdr
		INNER JOIN customer_plans USING (customer_id)
		LEFT JOIN call_rates ON
			cdr.direction = call_rates.direction AND
			customer_plans.plan_name = call_rates.plan_name AND
			cdr.tel LIKE call_rates.prefix || '%'
	ORDER BY cdr_id, prefix DESC;

COMMIT;

M sqitch.plan => sqitch.plan +3 -0
@@ 23,3 23,6 @@ cdr_charge [customer_plans plans cdr_with_charge] 2021-11-17T18:09:49Z Stephen P
insert_charge_for_cdr [cdr_charge cdr_with_charge transactions] 2021-11-23T14:41:15Z Stephen Paul Weber,,, <singpolyma@singpolyma-beefy> # Trigger to insert a transaction for the charge for this CDR
notify_low_balance [transactions balances] 2021-12-22T00:36:03Z Stephen Paul Weber,,, <singpolyma@singpolyma-beefy> # NOTIFY when balance dips low
@2022039 2022-02-08T15:35:37Z Stephen Paul Weber,,, <singpolyma@singpolyma-beefy> # Call limits and billing rollout

cdr_with_charge_faster [cdr_with_charge] 2022-02-08T17:12:16Z Stephen Paul Weber,,, <singpolyma@singpolyma-beefy> # Allow Postgres to push down WHERE over customer_id
@2022039.1 2022-02-08T17:16:11Z Stephen Paul Weber,,, <singpolyma@singpolyma-beefy> # Fix for cdr_with_charge performance

A verify/cdr_with_charge_faster.sql => verify/cdr_with_charge_faster.sql +7 -0
@@ 0,0 1,7 @@
-- Verify jmp:cdr_with_charge_faster on pg

BEGIN;

-- Check verify/cdr_with_charge.sql

ROLLBACK;