Skip to content

Commit

Permalink
feat: 無駄にメモリを確保してしまわないようにした
Browse files Browse the repository at this point in the history
  • Loading branch information
pantasystem committed Nov 28, 2023
1 parent bab96f2 commit 3f1f9ad
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ class NoteDTOEntityConverter @Inject constructor(
},
isRequireNyaize = isRequireNyaize,
),
maxReactionsPerAccount = 1
maxReactionsPerAccount = 1,
emojiNameMap = emojiNameMap,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ class TootDTOEntityConverter @Inject constructor(
imageCaches: Map<String, ImageCache>,
): Note {
return with(statusDTO) {
val emojis = emojis.map {
it.toEmoji(imageCaches[it.url]?.cachePath)
} + (emojiReactions?.mapNotNull {
it.getEmoji(imageCaches[it.url]?.cachePath)
} ?: emptyList())
Note(
id = Note.Id(account.accountId, id),
text = this.content,
Expand All @@ -103,11 +108,7 @@ class TootDTOEntityConverter @Inject constructor(
visibilityEx
),
localOnly = null,
emojis = emojis.map {
it.toEmoji(imageCaches[it.url]?.cachePath)
} + (emojiReactions?.mapNotNull {
it.getEmoji(imageCaches[it.url]?.cachePath)
} ?: emptyList()),
emojis = emojis,
app = null,
reactionCounts = emojiReactions?.map {
ReactionCount(
Expand Down Expand Up @@ -149,6 +150,7 @@ class TootDTOEntityConverter @Inject constructor(
pureText = text,
isReactionAvailable = isReactionAvailable
),
emojiNameMap = emojis.associateBy { it.name }
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ data class NoteRecord(

fun toModel(): Note {

val emojis = emojis?.map { CustomEmoji(
name = it.key,
url = it.value,
aspectRatio = customEmojiAspectRatioMap?.get(it.value)?.toFloatOrNull(),
cachePath = customEmojiUrlAndCachePathMap?.get(it.value)
) }
return Note(
id = Note.Id(accountId, noteId),
createdAt = createdAt.toInstant(),
Expand All @@ -221,12 +227,7 @@ data class NoteRecord(
it == entry.key
} ?: false
) },
emojis = emojis?.map { CustomEmoji(
name = it.key,
url = it.value,
aspectRatio = customEmojiAspectRatioMap?.get(it.value)?.toFloatOrNull(),
cachePath = customEmojiUrlAndCachePathMap?.get(it.value)
) },
emojis = emojis,
repliesCount = repliesCount,
fileIds = fileIds?.map { FileProperty.Id(accountId, it) },
poll = getPoll(),
Expand Down Expand Up @@ -266,6 +267,7 @@ data class NoteRecord(
else -> throw IllegalArgumentException()
},
app = null,
emojiNameMap = emojis?.associateBy { it.name }
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ data class Note(
val app: AppType.Misskey?,
val channelId: Channel.Id?,
val type: Type,
val maxReactionsPerAccount: Int) : Entity {
val maxReactionsPerAccount: Int,
val emojiNameMap: Map<String, CustomEmoji>?,
) : Entity {
class Id(
val accountId: Long,
val noteId: String,
Expand Down Expand Up @@ -131,9 +133,6 @@ data class Note(
val isAcceptingOnlyLikeReaction: Boolean =
type is Type.Misskey && type.isAcceptingOnlyLikeReaction

val emojiNameMap = emojis?.associateBy {
it.name
}

val isReacted: Boolean = reactionCounts.any {
it.me
Expand Down Expand Up @@ -303,6 +302,7 @@ fun Note.Companion.make(
app = app,
channelId = channelId,
type = type,
maxReactionsPerAccount = maxReactionsPerAccount
maxReactionsPerAccount = maxReactionsPerAccount,
emojiNameMap = emojis?.associateBy { it.name },
)
}

0 comments on commit 3f1f9ad

Please sign in to comment.