Remove tmp_indexes table

There's no need for it - we can read the index checksums and versions
from the master_index_archives rows we've just inserted.

Signed-off-by: Graham <gpe@openrs2.org>
bzip2
Graham 4 years ago
parent 2aab020e67
commit 48ce47ad7b
  1. 48
      archive/src/main/kotlin/org/openrs2/archive/cache/CacheImporter.kt

@ -188,7 +188,7 @@ public class CacheImporter @Inject constructor(
stmt.execute() stmt.execute()
} }
addMasterIndex( val id = addMasterIndex(
connection, connection,
MasterIndex(masterIndex, buf, uncompressed), MasterIndex(masterIndex, buf, uncompressed),
gameId, gameId,
@ -199,44 +199,18 @@ public class CacheImporter @Inject constructor(
overwrite = true overwrite = true
) )
connection.prepareStatement(
"""
CREATE TEMPORARY TABLE tmp_indexes (
archive_id uint1 NOT NULL,
crc32 INTEGER NOT NULL,
version INTEGER NOT NULL
) ON COMMIT DROP
""".trimIndent()
).use { stmt ->
stmt.execute()
}
connection.prepareStatement(
"""
INSERT INTO tmp_indexes (archive_id, crc32, version)
VALUES (?, ?, ?)
""".trimIndent()
).use { stmt ->
for ((i, entry) in masterIndex.entries.withIndex()) {
stmt.setInt(1, i)
stmt.setInt(2, entry.checksum)
stmt.setInt(3, entry.version)
stmt.addBatch()
}
stmt.executeBatch()
}
connection.prepareStatement( connection.prepareStatement(
""" """
SELECT c.data SELECT c.data
FROM tmp_indexes t FROM master_index_archives a
LEFT JOIN containers c ON c.crc32 = t.crc32 LEFT JOIN containers c ON c.crc32 = a.crc32
LEFT JOIN indexes i ON i.version = t.version AND i.container_id = c.id LEFT JOIN indexes i ON i.version = a.version AND i.container_id = c.id
ORDER BY t.archive_id ASC WHERE a.master_index_id = ?
ORDER BY a.archive_id ASC
""".trimIndent() """.trimIndent()
).use { stmt -> ).use { stmt ->
stmt.setInt(1, id)
stmt.executeQuery().use { rows -> stmt.executeQuery().use { rows ->
val indexes = mutableListOf<ByteBuf?>() val indexes = mutableListOf<ByteBuf?>()
try { try {
@ -361,7 +335,7 @@ public class CacheImporter @Inject constructor(
name: String?, name: String?,
description: String?, description: String?,
overwrite: Boolean overwrite: Boolean
) { ): Int {
val containerId = addContainer(connection, masterIndex) val containerId = addContainer(connection, masterIndex)
var masterIndexId: Int? = null var masterIndexId: Int? = null
@ -468,7 +442,7 @@ public class CacheImporter @Inject constructor(
stmt.execute() stmt.execute()
return@addMasterIndex return@addMasterIndex masterIndexId!!
} }
} }
@ -517,6 +491,8 @@ public class CacheImporter @Inject constructor(
stmt.executeBatch() stmt.executeBatch()
} }
return masterIndexId!!
} }
private fun readGroup(store: Store, archive: Int, index: Js5Index?, group: Int): Group? { private fun readGroup(store: Store, archive: Int, index: Js5Index?, group: Int): Group? {

Loading…
Cancel
Save