Fix propagating build numbers to loaders

Depending on the order of the blobs table, the previous query would
sometimes propagate a NULL version even if another resource used by the
same loader had a version number.

Signed-off-by: Graham <gpe@openrs2.org>
master
Graham 3 months ago
parent cc8f4cd9c1
commit 772ae1e8da
  1. 23
      archive/src/main/kotlin/org/openrs2/archive/client/ClientImporter.kt

@ -297,21 +297,30 @@ public class ClientImporter @Inject constructor(
} }
private fun resolveBuilds(connection: Connection) { private fun resolveBuilds(connection: Connection) {
connection.prepareStatement("""
UPDATE artifacts
SET
resolved_build_major = build_major,
resolved_build_minor = build_minor
""".trimIndent()).use { stmt ->
stmt.execute()
}
connection.prepareStatement( connection.prepareStatement(
""" """
UPDATE artifacts a UPDATE artifacts a
SET SET
resolved_build_major = t.build_major, resolved_build_major = coalesce(a.build_major, t.build_major),
resolved_build_minor = t.build_minor resolved_build_minor = coalesce(a.build_minor, t.build_minor)
FROM ( FROM (
SELECT DISTINCT ON (a1.blob_id) SELECT DISTINCT ON (a1.blob_id)
a1.blob_id, a1.blob_id,
coalesce(a1.build_major, a2.build_major) build_major, a2.build_major,
coalesce(a1.build_minor, a2.build_minor) build_minor a2.build_minor
FROM artifacts a1 FROM artifacts a1
LEFT JOIN artifact_links al ON al.blob_id = a1.blob_id JOIN artifact_links al ON al.blob_id = a1.blob_id
LEFT JOIN blobs b2 ON b2.sha1 = al.sha1 JOIN blobs b2 ON b2.sha1 = al.sha1
LEFT JOIN artifacts a2 ON a2.blob_id = b2.id JOIN artifacts a2 ON a2.blob_id = b2.id AND a2.build_major IS NOT NULL
ORDER BY a1.blob_id ASC, b2.id ASC ORDER BY a1.blob_id ASC, b2.id ASC
) t ) t
WHERE a.blob_id = t.blob_id WHERE a.blob_id = t.blob_id

Loading…
Cancel
Save