diff --git a/src/main/kotlin/net/taehui/twilight/system/DB.kt b/src/main/kotlin/net/taehui/twilight/system/DB.kt index 2aa7461..5e51023 100644 --- a/src/main/kotlin/net/taehui/twilight/system/DB.kt +++ b/src/main/kotlin/net/taehui/twilight/system/DB.kt @@ -650,59 +650,64 @@ pool.connection.use { Files.list(commentEntryPath).use { commentFilePaths -> commentFilePaths.forEach { commentFilePath -> - val commentID = FilenameUtils.removeExtension(commentFilePath.fileName.toString()) - it.prepareStatement( - """ - SELECT Audio_Multiplier - FROM tw_comment - WHERE Comment_ID = ? - """.trimIndent() - ).use { dbStatement -> - dbStatement.setString(1, commentID) - dbStatement.executeQuery().use { rows -> - if (rows.next()) { - val audioMultiplier = rows.getDouble("Audio_Multiplier") - val comment = - XZCompressorInputStream( - Files.readAllBytes(commentFilePath).inputStream() - ).use { - CommentOuterClass.Comment.parseFrom(it) - } - if (comment.audioMultipliersCount > 0) { - it.prepareStatement( - """ - UPDATE tw_comment - SET Lowest_Audio_Multiplier = ?, Highest_Audio_Multiplier = ? - WHERE Comment_ID = ? - """.trimIndent() - ).use { dbStatement -> - dbStatement.setDouble( - 1, - comment.audioMultipliersList.map { it.audioMultiplier } - .plus(audioMultiplier).min() - ) - dbStatement.setDouble( - 2, - comment.audioMultipliersList.map { it.audioMultiplier } - .plus(audioMultiplier).max() - ) - dbStatement.setString(3, commentID) - dbStatement.executeUpdate() - } - } else { - it.prepareStatement( - """ - UPDATE tw_comment - SET Lowest_Audio_Multiplier = Audio_Multiplier, Highest_Audio_Multiplier = Audio_Multiplier - WHERE Comment_ID = ? - """.trimIndent() - ).use { dbStatement -> - dbStatement.setString(1, commentID) - dbStatement.executeUpdate() + try { + val commentID = + FilenameUtils.removeExtension(commentFilePath.fileName.toString()) + it.prepareStatement( + """ + SELECT Audio_Multiplier + FROM tw_comment + WHERE Comment_ID = ? + """.trimIndent() + ).use { dbStatement -> + dbStatement.setString(1, commentID) + dbStatement.executeQuery().use { rows -> + if (rows.next()) { + val audioMultiplier = rows.getDouble("Audio_Multiplier") + val comment = + XZCompressorInputStream( + Files.readAllBytes(commentFilePath).inputStream() + ).use { + CommentOuterClass.Comment.parseFrom(it) + } + if (comment.audioMultipliersCount > 0) { + it.prepareStatement( + """ + UPDATE tw_comment + SET Lowest_Audio_Multiplier = ?, Highest_Audio_Multiplier = ? + WHERE Comment_ID = ? + """.trimIndent() + ).use { dbStatement -> + dbStatement.setDouble( + 1, + comment.audioMultipliersList.map { it.audioMultiplier } + .plus(audioMultiplier).min() + ) + dbStatement.setDouble( + 2, + comment.audioMultipliersList.map { it.audioMultiplier } + .plus(audioMultiplier).max() + ) + dbStatement.setString(3, commentID) + dbStatement.executeUpdate() + } + } else { + it.prepareStatement( + """ + UPDATE tw_comment + SET Lowest_Audio_Multiplier = Audio_Multiplier, Highest_Audio_Multiplier = Audio_Multiplier + WHERE Comment_ID = ? + """.trimIndent() + ).use { dbStatement -> + dbStatement.setString(1, commentID) + dbStatement.executeUpdate() + } } } } } + } catch (e: Throwable) { + logFault(e) } futureLearnCommentsStatus.incrementAndGet() }