diff --git a/src/main/kotlin/net/taehui/twilight/system/DB.kt b/src/main/kotlin/net/taehui/twilight/system/DB.kt index c49c745..8869d12 100644 --- a/src/main/kotlin/net/taehui/twilight/system/DB.kt +++ b/src/main/kotlin/net/taehui/twilight/system/DB.kt @@ -25,6 +25,8 @@ import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.collections.ArrayList +import kotlin.math.ceil +import kotlin.math.max import kotlin.math.pow object DB : Logger { @@ -2254,7 +2256,7 @@ var totalCount = 0 var topCount = 0 - var noteCount = 0 + var lastPage = 0 val notes = mutableListOf() return CompletableFuture.allOf(logFuture { @@ -2262,7 +2264,7 @@ if (isNotWant) { db.prepareStatement( """ - SELECT COUNT(Comment_ID) AS Total_Count, COUNT(DISTINCT tw_comment.Note_ID, Avatar) AS Top_Count, COUNT(DISTINCT tw_note.Note_ID) AS Note_Count + SELECT COUNT(Comment_ID) AS Total_Count, COUNT(DISTINCT Avatar, tw_comment.Note_ID) AS Top_Count, COUNT(DISTINCT tw_note.Note_ID) AS Note_Count FROM tw_note INNER JOIN tw_comment USING(Note_ID) """.trimIndent() @@ -2271,7 +2273,7 @@ if (rows.next()) { totalCount = rows.getInt("Total_Count") topCount = rows.getInt("Top_Count") - noteCount = rows.getInt("Note_Count") + lastPage = max(1.0, ceil(rows.getInt("Note_Count").toDouble() / viewUnit)).toInt() } } } @@ -2279,13 +2281,13 @@ db.prepareStatement( when (src) { 0 -> """ - SELECT COUNT(Comment_ID) AS Total_Count, COUNT(DISTINCT tw_comment.Note_ID, Avatar) AS Top_Count, COUNT(DISTINCT tw_note.Note_ID) AS Note_Count + SELECT COUNT(Comment_ID) AS Total_Count, COUNT(DISTINCT Avatar, tw_comment.Note_ID) AS Top_Count, COUNT(DISTINCT tw_note.Note_ID) AS Note_Count INNER JOIN tw_comment USING(Note_ID) WHERE MATCH(Title) AGAINST(? IN BOOLEAN MODE) """.trimIndent() 1 -> """ - SELECT COUNT(Comment_ID) AS Total_Count, COUNT(DISTINCT tw_comment.Note_ID, Avatar) AS Top_Count, COUNT(DISTINCT tw_note.Note_ID) AS Note_Count + SELECT COUNT(Comment_ID) AS Total_Count, COUNT(DISTINCT Avatar, tw_comment.Note_ID) AS Top_Count, COUNT(DISTINCT tw_note.Note_ID) AS Note_Count FROM tw_comment INNER JOIN tw_note USING(Note_ID) INNER JOIN tn_avatar ON tw_comment.Avatar = tn_avatar.Avatar_ID @@ -2293,13 +2295,13 @@ """.trimIndent() 2 -> """ - SELECT COUNT(Comment_ID) AS Total_Count, COUNT(DISTINCT tw_comment.Note_ID, Avatar) AS Top_Count, COUNT(DISTINCT tw_note.Note_ID) AS Note_Count + SELECT COUNT(Comment_ID) AS Total_Count, COUNT(DISTINCT Avatar, tw_comment.Note_ID) AS Top_Count, COUNT(DISTINCT tw_note.Note_ID) AS Note_Count INNER JOIN tw_comment USING(Note_ID) WHERE MATCH(Artist) AGAINST(? IN BOOLEAN MODE) """.trimIndent() 3 -> """ - SELECT COUNT(Comment_ID) AS Total_Count, COUNT(DISTINCT tw_comment.Note_ID, Avatar) AS Top_Count, COUNT(DISTINCT tw_note.Note_ID) AS Note_Count + SELECT COUNT(Comment_ID) AS Total_Count, COUNT(DISTINCT Avatar, tw_comment.Note_ID) AS Top_Count, COUNT(DISTINCT tw_note.Note_ID) AS Note_Count INNER JOIN tw_comment USING(Note_ID) WHERE MATCH(Genre) AGAINST(? IN BOOLEAN MODE) """.trimIndent() @@ -2313,7 +2315,7 @@ if (rows.next()) { totalCount = rows.getInt("Total_Count") topCount = rows.getInt("Top_Count") - noteCount = rows.getInt("Note_Count") + lastPage = max(1.0, ceil(rows.getInt("Note_Count").toDouble() / viewUnit)).toInt() } } } @@ -2323,7 +2325,7 @@ }, logFuture { val dataStatement = """ DISTINCT tw_note.Note_ID, Note_Variety, Artist, Title, Genre, Level_Text, tw_note.Level, ( - SELECT COUNT(DISTINCT Note_ID, Avatar) + SELECT COUNT(DISTINCT Avatar, Note_ID) FROM tw_comment WHERE tw_note.Note_ID = tw_comment.Note_ID ) AS Top_Count, ( @@ -2426,7 +2428,7 @@ object { val totalCount = totalCount val topCount = topCount - val noteCount = noteCount + val lastPage = lastPage val notes = notes } }