diff --git a/springboot/src/main/kotlin/com/goliath/emojihub/springboot/domain/emoji/service/EmojiService.kt b/springboot/src/main/kotlin/com/goliath/emojihub/springboot/domain/emoji/service/EmojiService.kt index 02fabaea..41792e45 100644 --- a/springboot/src/main/kotlin/com/goliath/emojihub/springboot/domain/emoji/service/EmojiService.kt +++ b/springboot/src/main/kotlin/com/goliath/emojihub/springboot/domain/emoji/service/EmojiService.kt @@ -51,21 +51,18 @@ class EmojiService( } else { user.saved_emojis } - var emojiList = mutableListOf() + val emojiArrayDeque = ArrayDeque() + var emojiList = listOf() if (emojiIdList != null && emojiIdList.size != 0) { for (emojiId in emojiIdList) { val emoji = emojiDao.getEmoji(emojiId) ?: continue - emojiList.add(emoji) - } - // sort - if (emojiList.size != 0) { - emojiList.sortByDescending { it.created_at } - // pagination - emojiList = emojiList.subList( - min((index - 1) * count, emojiList.size - 1), - min(index * count, emojiList.size) - ) + emojiArrayDeque.addFirst(emoji) } + // pagination + // FIXME: remind - CreatedEmojiList should already be sorted by created_at + val start = min((index - 1) * count, emojiArrayDeque.size - 1) + val end = min(index * count, emojiArrayDeque.size) + emojiList = emojiArrayDeque.toList().subList(start, end) } return emojiList }