From f8c44f1de4a323cda0b7217a3e07d8da392bdb6b Mon Sep 17 00:00:00 2001 From: Graham Date: Sun, 21 Feb 2021 13:44:45 +0000 Subject: [PATCH] Rename master_index_valid_{indexes,groups} to resolved_{indexes,groups} Signed-off-by: Graham --- .../org/openrs2/archive/cache/CacheExporter.kt | 12 ++++++------ .../org/openrs2/archive/cache/CacheImporter.kt | 2 +- .../org/openrs2/archive/migrations/V1__init.sql | 16 ++++++++-------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/archive/src/main/kotlin/org/openrs2/archive/cache/CacheExporter.kt b/archive/src/main/kotlin/org/openrs2/archive/cache/CacheExporter.kt index d570225c..3aa4551f 100644 --- a/archive/src/main/kotlin/org/openrs2/archive/cache/CacheExporter.kt +++ b/archive/src/main/kotlin/org/openrs2/archive/cache/CacheExporter.kt @@ -181,7 +181,7 @@ public class CacheExporter @Inject constructor( connection.prepareStatement( """ SELECT archive_id, group_id, data, version - FROM master_index_valid_groups + FROM resolved_groups WHERE master_index_id = ? """.trimIndent() ).use { stmt -> @@ -221,11 +221,11 @@ public class CacheExporter @Inject constructor( return database.execute { connection -> connection.prepareStatement( """ - SELECT v.archive_id, v.group_id, v.name_hash, n.name, (k.key).k0, (k.key).k1, (k.key).k2, (k.key).k3 - FROM master_index_valid_groups v - JOIN keys k ON k.id = v.key_id - LEFT JOIN names n ON n.hash = v.name_hash AND n.name ~ '^l(?:[0-9]|[1-9][0-9])_(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$' - WHERE v.master_index_id = ? + SELECT g.archive_id, g.group_id, g.name_hash, n.name, (k.key).k0, (k.key).k1, (k.key).k2, (k.key).k3 + FROM resolved_groups g + JOIN keys k ON k.id = g.key_id + LEFT JOIN names n ON n.hash = g.name_hash AND n.name ~ '^l(?:[0-9]|[1-9][0-9])_(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$' + WHERE g.master_index_id = ? """.trimIndent() ).use { stmt -> stmt.setInt(1, id) diff --git a/archive/src/main/kotlin/org/openrs2/archive/cache/CacheImporter.kt b/archive/src/main/kotlin/org/openrs2/archive/cache/CacheImporter.kt index bb74de5d..6ae3ba5b 100644 --- a/archive/src/main/kotlin/org/openrs2/archive/cache/CacheImporter.kt +++ b/archive/src/main/kotlin/org/openrs2/archive/cache/CacheImporter.kt @@ -276,7 +276,7 @@ public class CacheImporter @Inject constructor( """ SELECT ig.group_id FROM index_groups ig - LEFT JOIN master_index_valid_indexes i ON i.master_index_id = ? AND + LEFT JOIN resolved_indexes i ON i.master_index_id = ? AND i.archive_id = ? LEFT JOIN index_groups ig2 ON ig2.container_id = i.container_id AND ig2.group_id = ig.group_id AND ig2.crc32 = ig.crc32 AND ig2.version = ig.version 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 b974fae4..8394ec4f 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 @@ -134,7 +134,7 @@ CREATE TABLE names ( CREATE UNIQUE INDEX ON names (hash, name); -CREATE VIEW master_index_valid_indexes AS +CREATE VIEW resolved_indexes AS SELECT m.id AS master_index_id, a.archive_id, c.data, g.container_id FROM master_indexes m JOIN master_index_archives a ON a.master_index_id = m.id @@ -143,10 +143,10 @@ JOIN groups g ON g.archive_id = 255 AND g.group_id = a.archive_id::INTEGER AND JOIN containers c ON c.id = g.container_id AND c.crc32 = a.crc32 JOIN indexes i ON i.container_id = g.container_id AND i.version = a.version; -CREATE VIEW master_index_valid_groups (master_index_id, archive_id, group_id, name_hash, version, data, key_id) AS +CREATE VIEW resolved_groups (master_index_id, archive_id, group_id, name_hash, version, data, key_id) AS WITH i AS NOT MATERIALIZED ( SELECT master_index_id, archive_id, data, container_id - FROM master_index_valid_indexes + FROM resolved_indexes ) SELECT i.master_index_id, 255::uint1, i.archive_id::INTEGER, NULL, NULL, i.data, NULL FROM i @@ -174,20 +174,20 @@ CREATE UNIQUE INDEX ON master_index_archive_stats (master_index_id); CREATE MATERIALIZED VIEW master_index_group_stats (master_index_id, groups, valid_groups, keys, valid_keys) AS SELECT - v.master_index_id, + i.master_index_id, COUNT(*), COUNT(g.container_id), COUNT(*) FILTER (WHERE c.encrypted), COUNT(*) FILTER (WHERE c.key_id IS NOT NULL) -FROM master_index_valid_indexes v -JOIN index_groups ig ON ig.container_id = v.container_id -LEFT JOIN groups g ON g.archive_id = v.archive_id AND g.group_id = ig.group_id AND ( +FROM resolved_indexes i +JOIN index_groups ig ON ig.container_id = i.container_id +LEFT JOIN groups g ON g.archive_id = i.archive_id AND g.group_id = ig.group_id AND ( (g.version = ig.version AND NOT g.version_truncated) OR (g.version = ig.version & 65535 AND g.version_truncated) ) AND g.container_id IN (SELECT id FROM containers WHERE crc32 = ig.crc32) LEFT JOIN containers c ON c.id = g.container_id LEFT JOIN keys k ON k.id = c.key_id -GROUP BY v.master_index_id; +GROUP BY i.master_index_id; CREATE UNIQUE INDEX ON master_index_group_stats (master_index_id);