Skip to content

Commit

Permalink
fix: bulk insertの時に正しくリレーションがinsertされない問題を修正
Browse files Browse the repository at this point in the history
  • Loading branch information
pantasystem committed May 15, 2024
1 parent 0c0a795 commit 8ff14cc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ class SQLiteNoteDataSource @Inject constructor(
}.flatten().associateBy {
it.id
}
val existsReactionCountsMap = noteRelations.mapNotNull {
it.reactionCounts
val existsReactionCountsMap = existsNotes.mapNotNull {
it.value.reactionCounts
}.flatten().associateBy {
it.id
}
Expand All @@ -231,17 +231,17 @@ class SQLiteNoteDataSource @Inject constructor(
}.flatten().associateBy {
it.id
}
val existsCustomEmojis = noteRelations.mapNotNull {
it.customEmojis
val existsCustomEmojis = existsNotes.mapNotNull {
it.value.customEmojis
}.flatten().associateBy {
it.id
}

val pollChoices = noteRelations.mapNotNull {
it.pollChoices
}.flatten()
val existsPollChoices = noteRelations.mapNotNull {
it.pollChoices
val existsPollChoices = existsNotes.mapNotNull {
it.value.pollChoices
}.flatten()

val mastodonNotes = needInsertNotes.filter {
Expand Down Expand Up @@ -422,14 +422,10 @@ class SQLiteNoteDataSource @Inject constructor(

val updateOrInsertList = reactionCountsMap.mapNotNull { (key, value) ->
val exists = existsNoteReactionCountMap[key]
if (exists == null) {
if (exists == null || exists != value) {
value
} else {
if (exists != value) {
value
} else {
null
}
null
}
}

Expand All @@ -450,14 +446,10 @@ class SQLiteNoteDataSource @Inject constructor(

val updateOrInsertList = customEmojis.mapNotNull { emoji ->
val exists = existsCustomEmojis[emoji.key]
if (exists == null) {
if (exists == null || exists != emoji.value) {
emoji.value
} else {
if (exists != emoji.value) {
emoji.value
} else {
null
}
null
}
}

Expand All @@ -476,14 +468,10 @@ class SQLiteNoteDataSource @Inject constructor(
val exists = existsPollChoices.find {
it.id == choice.id
}
if (exists == null) {
if (exists == null || exists != choice) {
choice
} else {
if (exists != choice) {
choice
} else {
null
}
null
}
}
noteDAO.insertPollChoices(updateOrInsertList)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.pantasystem.milktea.model.note.reaction

import kotlinx.coroutines.delay
import net.pantasystem.milktea.common.flatMapCancellableCatching
import net.pantasystem.milktea.common.runCancellableCatching
import net.pantasystem.milktea.model.UseCase
Expand Down Expand Up @@ -86,6 +87,7 @@ class ToggleReactionUseCase @Inject constructor(
// NOTE: Suggestionを表示するためにユーザのデータが必要になるので、キャッシュを更新しておく
userRepository.sync(note.userId).getOrThrow()
}.flatMapCancellableCatching {
delay(100)
noteRepository.sync(noteId)
}
}
Expand Down

0 comments on commit 8ff14cc

Please sign in to comment.