mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-31 15:19:29 +07:00
perf: Don't re-substring multiplayer file name every time you do anything, dammit
This commit is contained in:
@ -302,7 +302,7 @@ class OnlineMultiplayer {
|
||||
fun changeGameName(game: OnlineMultiplayerGame, newName: String, onException: (Exception?)->Unit) {
|
||||
debug("Changing name of game %s to", game.name, newName)
|
||||
val oldPreview = game.preview ?: throw game.error!!
|
||||
val oldLastUpdate = game.lastUpdate
|
||||
val oldLastUpdate = game.getLastUpdate()
|
||||
val oldName = game.name
|
||||
|
||||
val newFileHandle = files.saveGame(oldPreview, newName, onException)
|
||||
|
@ -30,17 +30,16 @@ class OnlineMultiplayerGame(
|
||||
lastOnlineUpdate: Instant? = null
|
||||
) {
|
||||
private val lastOnlineUpdate: AtomicReference<Instant?> = AtomicReference(lastOnlineUpdate)
|
||||
val lastUpdate: Instant
|
||||
get() {
|
||||
val lastFileUpdateTime = Instant.ofEpochMilli(fileHandle.lastModified())
|
||||
val lastOnlineUpdateTime = lastOnlineUpdate.get()
|
||||
return if (lastOnlineUpdateTime == null || lastFileUpdateTime.isLargerThan(lastOnlineUpdateTime)) {
|
||||
lastFileUpdateTime
|
||||
} else {
|
||||
lastOnlineUpdateTime
|
||||
}
|
||||
fun getLastUpdate(): Instant {
|
||||
val lastFileUpdateTime = Instant.ofEpochMilli(fileHandle.lastModified())
|
||||
val lastOnlineUpdateTime = lastOnlineUpdate.get()
|
||||
return if (lastOnlineUpdateTime == null || lastFileUpdateTime.isLargerThan(lastOnlineUpdateTime)) {
|
||||
lastFileUpdateTime
|
||||
} else {
|
||||
lastOnlineUpdateTime
|
||||
}
|
||||
val name get() = fileHandle.name()
|
||||
}
|
||||
val name = fileHandle.name()
|
||||
var error: Exception? = null
|
||||
|
||||
init {
|
||||
|
@ -42,7 +42,7 @@ object MultiplayerHelpers {
|
||||
val (message) = LoadGameScreen.getLoadExceptionMessage(ex, "Error while refreshing:")
|
||||
descriptionText.appendLine(message)
|
||||
}
|
||||
val lastUpdate = multiplayerGame.lastUpdate
|
||||
val lastUpdate = multiplayerGame.getLastUpdate()
|
||||
descriptionText.appendLine("Last refresh: [${Duration.between(lastUpdate, Instant.now()).formatShort()}] ago".tr())
|
||||
val preview = multiplayerGame.preview
|
||||
if (preview?.currentPlayer != null) {
|
||||
|
Reference in New Issue
Block a user