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 6ab0602 commit eb93a4e
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,13 @@ internal class CustomEmojiRepositoryImpl @Inject constructor(

override suspend fun findByNames(host: String, names: List<String>): Result<List<CustomEmoji>> = runCancellableCatching {
withContext(ioDispatcher) {
val records = customEmojiDAO.findByNames(host, names)
val allEmojis = customEmojiCache.getMap(host)
val inMemEmojis = names.mapNotNull {
allEmojis?.get(it)
}
val records = customEmojiDAO.findByNames(host, names.filter {
allEmojis?.get(it) == null
})
val aspects = aspectRatioDataSource.findIn(records.mapNotNull {
it.url ?: it.uri
}).getOrElse { emptyList() }.associateBy {
Expand All @@ -221,7 +227,7 @@ internal class CustomEmojiRepositoryImpl @Inject constructor(
}).associateBy {
it.sourceUrl
}
records.map { record ->
inMemEmojis + records.map { record ->
record.toModel(
aspects[record.url ?: record.uri]?.aspectRatio,
fileCaches[record.url ?: record.uri]?.cachePath,
Expand Down

0 comments on commit eb93a4e

Please sign in to comment.