Full Circ Count View Amplifies Legacy Circs
authorDan Wells <dbw2@calvin.edu>
Thu, 29 Sep 2011 13:23:49 +0000 (09:23 -0400)
committerMike Rylander <mrylander@gmail.com>
Tue, 15 Nov 2011 21:18:54 +0000 (16:18 -0500)
The current extend_reported.full_circ_count sums the legacy circ count
column, but this results in amplifying the count by the number of current
circs in the system.  This commit adds the legacy count to the GROUP BY
instead of summing it.

Signed-off-by: Dan Wells <dbw2@calvin.edu>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/sql/Pg/extend-reporter.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fix_full_circ_count_view.sql [new file with mode: 0644]

index 6a13568..3643631 100644 (file)
@@ -26,12 +26,12 @@ CREATE TABLE extend_reporter.legacy_circ_count (
 );
 
 CREATE OR REPLACE VIEW extend_reporter.full_circ_count AS
- SELECT cp.id, COALESCE(sum(c.circ_count), 0::bigint) + COALESCE(count(circ.id), 0::bigint) + COALESCE(count(acirc.id), 0::bigint) AS circ_count
+ SELECT cp.id, COALESCE(c.circ_count, 0::bigint) + COALESCE(count(circ.id), 0::bigint) + COALESCE(count(acirc.id), 0::bigint) AS circ_count
    FROM asset."copy" cp
    LEFT JOIN extend_reporter.legacy_circ_count c USING (id)
    LEFT JOIN "action".circulation circ ON circ.target_copy = cp.id
    LEFT JOIN "action".aged_circulation acirc ON acirc.target_copy = cp.id
-  GROUP BY cp.id;
+  GROUP BY cp.id, c.circ_count;
 
 CREATE OR REPLACE VIEW extend_reporter.global_bibs_by_holding_update AS
   SELECT DISTINCT ON (id) id, holding_update, update_type
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fix_full_circ_count_view.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fix_full_circ_count_view.sql
new file mode 100644 (file)
index 0000000..eb558c3
--- /dev/null
@@ -0,0 +1,7 @@
+CREATE OR REPLACE VIEW extend_reporter.full_circ_count AS
+ SELECT cp.id, COALESCE(c.circ_count, 0::bigint) + COALESCE(count(circ.id), 0::bigint) + COALESCE(count(acirc.id), 0::bigint) AS circ_count
+   FROM asset."copy" cp
+   LEFT JOIN extend_reporter.legacy_circ_count c USING (id)
+   LEFT JOIN "action".circulation circ ON circ.target_copy = cp.id
+   LEFT JOIN "action".aged_circulation acirc ON acirc.target_copy = cp.id
+  GROUP BY cp.id, c.circ_count;