|
|
|
@ -27,7 +27,6 @@ import java.time.OffsetDateTime |
|
|
|
|
import java.time.ZoneOffset |
|
|
|
|
import javax.inject.Inject |
|
|
|
|
import javax.inject.Singleton |
|
|
|
|
import kotlin.math.min |
|
|
|
|
|
|
|
|
|
@Singleton |
|
|
|
|
public class CacheImporter @Inject constructor( |
|
|
|
@ -341,14 +340,13 @@ public class CacheImporter @Inject constructor( |
|
|
|
|
val containerId = addContainer(connection, masterIndex) |
|
|
|
|
var masterIndexId: Int? = null |
|
|
|
|
|
|
|
|
|
var newBuild: Int? |
|
|
|
|
var newTimestamp: Instant? |
|
|
|
|
var newName: String? |
|
|
|
|
var newDescription: String? |
|
|
|
|
|
|
|
|
|
connection.prepareStatement( |
|
|
|
|
""" |
|
|
|
|
SELECT id, game_id, build, timestamp, name, description |
|
|
|
|
SELECT id, game_id, timestamp, name, description |
|
|
|
|
FROM master_indexes |
|
|
|
|
WHERE container_id = ? AND format = ?::master_index_format |
|
|
|
|
FOR UPDATE |
|
|
|
@ -365,25 +363,12 @@ public class CacheImporter @Inject constructor( |
|
|
|
|
if (masterIndexId != null) { |
|
|
|
|
val oldGameId = rows.getInt(2) |
|
|
|
|
|
|
|
|
|
var oldBuild: Int? = rows.getInt(3) |
|
|
|
|
if (rows.wasNull()) { |
|
|
|
|
oldBuild = null |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val oldTimestamp: Instant? = rows.getTimestamp(4)?.toInstant() |
|
|
|
|
val oldName: String? = rows.getString(5) |
|
|
|
|
val oldDescription: String? = rows.getString(6) |
|
|
|
|
val oldTimestamp: Instant? = rows.getTimestamp(3)?.toInstant() |
|
|
|
|
val oldName: String? = rows.getString(4) |
|
|
|
|
val oldDescription: String? = rows.getString(5) |
|
|
|
|
|
|
|
|
|
check(oldGameId == gameId) |
|
|
|
|
|
|
|
|
|
if (oldBuild != null && build != null) { |
|
|
|
|
newBuild = min(oldBuild, build) |
|
|
|
|
} else if (oldBuild != null) { |
|
|
|
|
newBuild = oldBuild |
|
|
|
|
} else { |
|
|
|
|
newBuild = build |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (oldTimestamp != null && timestamp != null) { |
|
|
|
|
newTimestamp = if (oldTimestamp.isBefore(timestamp)) { |
|
|
|
|
oldTimestamp |
|
|
|
@ -416,7 +401,6 @@ public class CacheImporter @Inject constructor( |
|
|
|
|
newDescription = description |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
newBuild = build |
|
|
|
|
newTimestamp = timestamp |
|
|
|
|
newName = name |
|
|
|
|
newDescription = description |
|
|
|
@ -428,50 +412,44 @@ public class CacheImporter @Inject constructor( |
|
|
|
|
connection.prepareStatement( |
|
|
|
|
""" |
|
|
|
|
UPDATE master_indexes |
|
|
|
|
SET build = ?, timestamp = ?, name = ?, description = ? |
|
|
|
|
SET timestamp = ?, name = ?, description = ? |
|
|
|
|
WHERE id = ? |
|
|
|
|
""".trimIndent() |
|
|
|
|
).use { stmt -> |
|
|
|
|
stmt.setObject(1, newBuild, Types.INTEGER) |
|
|
|
|
|
|
|
|
|
if (newTimestamp != null) { |
|
|
|
|
val offsetDateTime = OffsetDateTime.ofInstant(newTimestamp, ZoneOffset.UTC) |
|
|
|
|
stmt.setObject(2, offsetDateTime, Types.TIMESTAMP_WITH_TIMEZONE) |
|
|
|
|
stmt.setObject(1, offsetDateTime, Types.TIMESTAMP_WITH_TIMEZONE) |
|
|
|
|
} else { |
|
|
|
|
stmt.setNull(2, Types.TIMESTAMP_WITH_TIMEZONE) |
|
|
|
|
stmt.setNull(1, Types.TIMESTAMP_WITH_TIMEZONE) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
stmt.setString(3, newName) |
|
|
|
|
stmt.setString(4, newDescription) |
|
|
|
|
stmt.setInt(5, masterIndexId!!) |
|
|
|
|
stmt.setString(2, newName) |
|
|
|
|
stmt.setString(3, newDescription) |
|
|
|
|
stmt.setInt(4, masterIndexId!!) |
|
|
|
|
|
|
|
|
|
stmt.execute() |
|
|
|
|
|
|
|
|
|
return@addMasterIndex masterIndexId!! |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
connection.prepareStatement( |
|
|
|
|
""" |
|
|
|
|
INSERT INTO master_indexes (container_id, format, game_id, build, timestamp, name, description) |
|
|
|
|
VALUES (?, ?::master_index_format, ?, ?, ?, ?, ?) |
|
|
|
|
INSERT INTO master_indexes (container_id, format, game_id, timestamp, name, description) |
|
|
|
|
VALUES (?, ?::master_index_format, ?, ?, ?, ?) |
|
|
|
|
RETURNING id |
|
|
|
|
""".trimIndent() |
|
|
|
|
).use { stmt -> |
|
|
|
|
stmt.setLong(1, containerId) |
|
|
|
|
stmt.setString(2, masterIndex.index.format.name.toLowerCase()) |
|
|
|
|
stmt.setInt(3, gameId) |
|
|
|
|
stmt.setObject(4, newBuild, Types.INTEGER) |
|
|
|
|
|
|
|
|
|
if (newTimestamp != null) { |
|
|
|
|
val offsetDateTime = OffsetDateTime.ofInstant(newTimestamp, ZoneOffset.UTC) |
|
|
|
|
stmt.setObject(5, offsetDateTime, Types.TIMESTAMP_WITH_TIMEZONE) |
|
|
|
|
stmt.setObject(4, offsetDateTime, Types.TIMESTAMP_WITH_TIMEZONE) |
|
|
|
|
} else { |
|
|
|
|
stmt.setNull(5, Types.TIMESTAMP_WITH_TIMEZONE) |
|
|
|
|
stmt.setNull(4, Types.TIMESTAMP_WITH_TIMEZONE) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
stmt.setString(6, newName) |
|
|
|
|
stmt.setString(7, newDescription) |
|
|
|
|
stmt.setString(5, newName) |
|
|
|
|
stmt.setString(6, newDescription) |
|
|
|
|
|
|
|
|
|
stmt.executeQuery().use { rows -> |
|
|
|
|
check(rows.next()) |
|
|
|
@ -517,6 +495,21 @@ public class CacheImporter @Inject constructor( |
|
|
|
|
|
|
|
|
|
stmt.executeBatch() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (build != null) { |
|
|
|
|
connection.prepareStatement( |
|
|
|
|
""" |
|
|
|
|
INSERT INTO master_index_builds (master_index_id, build) |
|
|
|
|
VALUES (?, ?) |
|
|
|
|
ON CONFLICT DO NOTHING |
|
|
|
|
""".trimIndent() |
|
|
|
|
).use { stmt -> |
|
|
|
|
stmt.setInt(1, masterIndexId!!) |
|
|
|
|
stmt.setInt(2, build) |
|
|
|
|
stmt.execute() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return masterIndexId!! |
|
|
|
|
} |
|
|
|
|