From f6961a50f15d32d05e8613b14cbb09558a2bce0e Mon Sep 17 00:00:00 2001 From: Graham Date: Sat, 27 Mar 2021 23:04:31 +0000 Subject: [PATCH] Add cache size in bytes to master_index_stats Signed-off-by: Graham --- .../org/openrs2/archive/migrations/V1__init.sql | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/archive/src/main/resources/org/openrs2/archive/migrations/V1__init.sql b/archive/src/main/resources/org/openrs2/archive/migrations/V1__init.sql index 6edbc023..063b27a9 100644 --- a/archive/src/main/resources/org/openrs2/archive/migrations/V1__init.sql +++ b/archive/src/main/resources/org/openrs2/archive/migrations/V1__init.sql @@ -210,7 +210,8 @@ CREATE MATERIALIZED VIEW master_index_stats ( valid_groups, groups, valid_keys, - keys + keys, + size ) AS SELECT m.id, @@ -219,13 +220,15 @@ SELECT COALESCE(g.valid_groups, 0), COALESCE(g.groups, 0), COALESCE(g.valid_keys, 0), - COALESCE(g.keys, 0) + COALESCE(g.keys, 0), + COALESCE(a.size, 0) + COALESCE(g.size, 0) FROM master_indexes m LEFT JOIN ( SELECT a.master_index_id, COUNT(*) FILTER (WHERE c.id IS NOT NULL OR (a.version = 0 AND a.crc32 = 0)) AS valid_indexes, - COUNT(*) AS indexes + COUNT(*) AS indexes, + SUM(length(c.data)) FILTER (WHERE c.id IS NOT NULL) AS size FROM master_index_archives a LEFT JOIN resolve_index(a.archive_id, a.crc32, a.version) c ON TRUE GROUP BY a.master_index_id @@ -236,7 +239,8 @@ LEFT JOIN ( COUNT(*) FILTER (WHERE c.id IS NOT NULL) AS valid_groups, COUNT(*) AS groups, COUNT(*) FILTER (WHERE c.key_id IS NOT NULL) AS valid_keys, - COUNT(*) FILTER (WHERE c.encrypted) AS keys + COUNT(*) FILTER (WHERE c.encrypted) AS keys, + SUM(length(c.data)) FILTER (WHERE c.id IS NOT NULL) AS size FROM resolved_indexes i JOIN index_groups ig ON ig.container_id = i.container_id LEFT JOIN resolve_group(i.archive_id, ig.group_id, ig.crc32, ig.version) c ON TRUE