Skip to content

Commit

Permalink
feat: io dispatcher上で実行するようにした
Browse files Browse the repository at this point in the history
  • Loading branch information
pantasystem committed Oct 28, 2023
1 parent 372f7c5 commit ee1459a
Showing 1 changed file with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,10 @@ class MediatorUserDataSource @Inject constructor(
}
}

override suspend fun addAll(users: List<User>): Result<Map<User.Id, AddResult>> =
runCancellableCatching {
override suspend fun addAll(
users: List<User>
): Result<Map<User.Id, AddResult>> = runCancellableCatching {
withContext(ioDispatcher) {
val existsUsersInMemory = users.associate {
it.id to memCache.get(it.id)
}
Expand Down Expand Up @@ -248,6 +250,8 @@ class MediatorUserDataSource @Inject constructor(
}.toMap()
}

}

override suspend fun remove(user: User): Result<Boolean> = runCancellableCatching {
runCancellableCatching {
memCache.remove(user.id)
Expand Down Expand Up @@ -391,8 +395,13 @@ class MediatorUserDataSource @Inject constructor(
}
}

private suspend fun replacePinnedNoteIdsIfNeed(dbId: Long, user: User.Detail, record: UserRelated?, recordToDetailed: User.Detail? = (record?.toModel() as? User.Detail?)) {
val recordDetail = recordToDetailed?: (record?.toModel() as? User.Detail?)
private suspend fun replacePinnedNoteIdsIfNeed(
dbId: Long,
user: User.Detail,
record: UserRelated?,
recordToDetailed: User.Detail? = (record?.toModel() as? User.Detail?)
) {
val recordDetail = recordToDetailed ?: (record?.toModel() as? User.Detail?)
if (recordDetail?.info?.pinnedNoteIds?.toSet() != user.info.pinnedNoteIds?.toSet()) {
// NOTE: 更新系の場合は一度削除する
if (record != null) {
Expand All @@ -408,8 +417,13 @@ class MediatorUserDataSource @Inject constructor(
}
}

private suspend fun replaceFieldsIfNeed(dbId: Long, user: User.Detail, record: UserRelated?, recordToDetailed: User.Detail? = (record?.toModel() as? User.Detail?)) {
val recordDetail = recordToDetailed?: (record?.toModel() as? User.Detail?)
private suspend fun replaceFieldsIfNeed(
dbId: Long,
user: User.Detail,
record: UserRelated?,
recordToDetailed: User.Detail? = (record?.toModel() as? User.Detail?)
) {
val recordDetail = recordToDetailed ?: (record?.toModel() as? User.Detail?)
if (recordDetail?.info?.fields?.toSet() != user.info.fields.toSet()) {
if (record != null) {
userDao.detachUserFields(dbId)
Expand Down

0 comments on commit ee1459a

Please sign in to comment.