From ca4cc2f3e9e279607b8e34c6e409300c500aab60 Mon Sep 17 00:00:00 2001 From: Yuichiro Kinoshita Date: Sat, 28 Oct 2023 00:37:27 +0900 Subject: [PATCH 01/10] =?UTF-8?q?feat:=20disk=20io=E3=82=92=E3=81=A7?= =?UTF-8?q?=E3=81=8D=E3=82=8B=E3=81=A0=E3=81=91=E5=B0=91=E3=81=AA=E3=81=8F?= =?UTF-8?q?=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E3=81=99?= =?UTF-8?q?=E3=82=8B=E3=81=9F=E3=82=81=E3=81=AB=E4=B8=80=E6=8B=AC=E3=81=A7?= =?UTF-8?q?=E5=87=A6=E7=90=86=E3=82=92=E5=AE=9F=E8=A1=8C=E3=81=A7=E3=81=8D?= =?UTF-8?q?=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../note/NoteDataSourceAdder.kt | 84 ++++++++++++++++++- .../note/TimelinePagingStoreImpl.kt | 12 ++- 2 files changed, 89 insertions(+), 7 deletions(-) diff --git a/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/note/NoteDataSourceAdder.kt b/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/note/NoteDataSourceAdder.kt index 8f1b5e177d..01aaec8842 100644 --- a/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/note/NoteDataSourceAdder.kt +++ b/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/note/NoteDataSourceAdder.kt @@ -40,7 +40,81 @@ class NoteDataSourceAdder @Inject constructor( } - suspend fun addNoteDtoToDataSource(account: Account, noteDTO: NoteDTO, skipExists: Boolean = false, instanceType: InstanceInfoType? = null): Note { + suspend fun addNoteDtoListToDataSource( + account: Account, + noteDTOs: List, + skipExists: Boolean = false, + instanceType: InstanceInfoType? = null + ): List { + val info = instanceType?.takeIf { + it.uri == account.normalizedInstanceUri + } ?: instanceInfoService.find(account.normalizedInstanceUri).getOrNull() + val entities = noteDTOs.map { + it.toEntities( + account, + userDTOEntityConverter, + noteDTOEntityConverter, + filePropertyDTOEntityConverter, + info, + ) + + } + if (skipExists) { + userDataSource.addAll( + entities.flatMap { + it.users + }.filterNot { + userDataSource.get(it.id).isSuccess + } + ).onFailure { + logger.error("UserDataSourceへの追加に失敗", it) + } + noteDataSource.addAll( + entities.flatMap { + it.notes + }.filterNot { + noteDataSource.exists(it.id) + } + ).onFailure { + logger.error("NoteDataSourceへの追加に失敗", it) + } + filePropertyDataSource.addAll( + entities.flatMap { + it.files + }.filterNot { + filePropertyDataSource.find(it.id).isSuccess + } + ).onFailure { + logger.error("FilePropertyDataSourceへの追加に失敗", it) + } + } else { + userDataSource.addAll(entities.flatMap { + it.users + }).onFailure { + logger.error("UserDataSourceへの追加に失敗", it) + } + noteDataSource.addAll(entities.flatMap { + it.notes + }).onFailure { + logger.error("NoteDataSourceへの追加に失敗", it) + } + filePropertyDataSource.addAll(entities.flatMap { + it.files + }).onFailure { + logger.error("FilePropertyDataSourceへの追加に失敗", it) + } + } + return entities.map { + it.note + } + } + + suspend fun addNoteDtoToDataSource( + account: Account, + noteDTO: NoteDTO, + skipExists: Boolean = false, + instanceType: InstanceInfoType? = null + ): Note { val info = instanceType?.takeIf { it.uri == account.normalizedInstanceUri } ?: instanceInfoService.find(account.normalizedInstanceUri).getOrNull() @@ -94,7 +168,11 @@ class NoteDataSourceAdder @Inject constructor( return entities.note } - suspend fun addTootStatusDtoIntoDataSource(account: Account, status: TootStatusDTO, skipExists: Boolean = false): Note { + suspend fun addTootStatusDtoIntoDataSource( + account: Account, + status: TootStatusDTO, + skipExists: Boolean = false + ): Note { val entities = status.toEntities(tootDTOEntityConverter, account) if (skipExists) { userDataSource.addAll( @@ -193,7 +271,7 @@ private suspend fun NoteDTO.pickEntities( noteDTOEntityConverter: NoteDTOEntityConverter, filePropertyDTOEntityConverter: FilePropertyDTOEntityConverter, instanceType: InstanceInfoType?, - ) { +) { val (note, user) = this.toNoteAndUser( account, userDTOEntityConverter, diff --git a/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/note/TimelinePagingStoreImpl.kt b/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/note/TimelinePagingStoreImpl.kt index a305ba3757..43ea1878cb 100644 --- a/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/note/TimelinePagingStoreImpl.kt +++ b/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/note/TimelinePagingStoreImpl.kt @@ -104,10 +104,14 @@ internal class TimelinePagingStoreImpl( override suspend fun convertAll(list: List): List { val info = getCurrentInstanceInfo(getAccount().normalizedInstanceUri) - return list.filter { - it.promotionId == null || it.tmpFeaturedId == null - }.map { - noteAdder.addNoteDtoToDataSource(getAccount.invoke(), it, instanceType = info).id + return noteAdder.addNoteDtoListToDataSource( + getAccount.invoke(), + list.filter { + it.promotionId == null || it.tmpFeaturedId == null + }, + instanceType = info + ).map { + it.id } } From 1fd74076987fb1d7633a892b652d1b93a38864f1 Mon Sep 17 00:00:00 2001 From: Yuichiro Kinoshita Date: Sat, 28 Oct 2023 00:43:27 +0900 Subject: [PATCH 02/10] =?UTF-8?q?feat:=20=E4=B8=80=E6=8B=AC=E5=A4=89?= =?UTF-8?q?=E6=8F=9B=E5=87=A6=E7=90=86=E3=82=92=E3=81=A7=E3=81=8D=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/converters/NoteDTOEntityConverter.kt | 63 +++++++++++++++++-- 1 file changed, 58 insertions(+), 5 deletions(-) diff --git a/modules/data/src/main/java/net/pantasystem/milktea/data/converters/NoteDTOEntityConverter.kt b/modules/data/src/main/java/net/pantasystem/milktea/data/converters/NoteDTOEntityConverter.kt index 260012655a..ba192e4720 100644 --- a/modules/data/src/main/java/net/pantasystem/milktea/data/converters/NoteDTOEntityConverter.kt +++ b/modules/data/src/main/java/net/pantasystem/milktea/data/converters/NoteDTOEntityConverter.kt @@ -8,6 +8,7 @@ import net.pantasystem.milktea.model.account.Account import net.pantasystem.milktea.model.channel.Channel import net.pantasystem.milktea.model.drive.FileProperty import net.pantasystem.milktea.model.emoji.CustomEmojiAspectRatioDataSource +import net.pantasystem.milktea.model.image.ImageCache import net.pantasystem.milktea.model.image.ImageCacheRepository import net.pantasystem.milktea.model.instance.InstanceInfoService import net.pantasystem.milktea.model.instance.InstanceInfoType @@ -26,15 +27,48 @@ class NoteDTOEntityConverter @Inject constructor( private val instanceInfoService: InstanceInfoService, ) { - suspend fun convert(account: Account, noteDTO: NoteDTO, instanceInfoType: InstanceInfoType? = null): Note { - val emojis = (noteDTO.emojiList + (noteDTO.reactionEmojiList)) - + suspend fun convertAll( + account: Account, + noteDTOs: List, + instanceInfoType: InstanceInfoType? = null + ): List { + val emojis = noteDTOs.flatMap { + it.emojiList + (it.reactionEmojiList) + } val instanceInfo = instanceInfoType?.takeIf { it.uri == account.normalizedInstanceUri } ?: instanceInfoService.find(account.normalizedInstanceUri).getOrNull() + val aspects = customEmojiAspectRatioDataSource.findIn(emojis.mapNotNull { + it.url ?: it.uri + }).getOrElse { + emptyList() + }.associate { + it.uri to it.aspectRatio + } + val fileCaches = imageCacheRepository.findBySourceUrls(emojis.mapNotNull { + it.url ?: it.uri + }).associateBy { + it.sourceUrl + } + + return noteDTOs.map { + convert( + account = account, + noteDTO = it, + instanceInfoType = instanceInfo, + aspects = aspects, + fileCaches = fileCaches + ) + } + } + + suspend fun convert( + account: Account, + noteDTO: NoteDTO, + instanceInfoType: InstanceInfoType? = null + ): Note { + val emojis = noteDTO.emojiList - val isRequireNyaize = (instanceInfo?.isRequirePerformNyaizeFrontend ?: false) - && (noteDTO.user.isCat ?: false) val aspects = customEmojiAspectRatioDataSource.findIn(emojis.mapNotNull { it.url ?: it.uri }).getOrElse { @@ -47,6 +81,25 @@ class NoteDTOEntityConverter @Inject constructor( }).associateBy { it.sourceUrl } + return convert( + account = account, + noteDTO = noteDTO, + instanceInfoType = instanceInfoType, + aspects = aspects, + fileCaches = fileCaches + ) + } + + private fun convert( + account: Account, + noteDTO: NoteDTO, + instanceInfoType: InstanceInfoType? = null, + aspects: Map, + fileCaches: Map + ): Note { + val emojis = noteDTO.emojiList + val isRequireNyaize = (instanceInfoType?.isRequirePerformNyaizeFrontend ?: false) + && (noteDTO.user.isCat ?: false) val visibility = Visibility( noteDTO.visibility ?: NoteVisibilityType.Public, isLocalOnly = noteDTO.localOnly ?: false, From bdf622720c378fccb510194a63cc4dec656cb7d3 Mon Sep 17 00:00:00 2001 From: Yuichiro Kinoshita Date: Sat, 28 Oct 2023 00:56:09 +0900 Subject: [PATCH 03/10] =?UTF-8?q?feat:=20=E4=B8=80=E6=8B=AC=E5=A4=89?= =?UTF-8?q?=E6=8F=9B=E3=81=8A=E3=82=88=E3=81=B3=E8=BF=BD=E5=8A=A0=E3=81=A7?= =?UTF-8?q?=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../infrastructure/MisskeyEntityConverters.kt | 8 ++ .../note/NoteDataSourceAdder.kt | 80 ++++++++++--------- .../note/TimelinePagingStoreImpl.kt | 4 +- 3 files changed, 50 insertions(+), 42 deletions(-) diff --git a/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/MisskeyEntityConverters.kt b/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/MisskeyEntityConverters.kt index fada1d0efd..ab4b2af2ad 100644 --- a/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/MisskeyEntityConverters.kt +++ b/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/MisskeyEntityConverters.kt @@ -2,6 +2,7 @@ package net.pantasystem.milktea.data.infrastructure import net.pantasystem.milktea.api.misskey.groups.GroupDTO import net.pantasystem.milktea.api.misskey.list.UserListDTO +import net.pantasystem.milktea.api.misskey.notes.NoteDTO import net.pantasystem.milktea.model.account.Account import net.pantasystem.milktea.model.drive.FileProperty import net.pantasystem.milktea.model.group.Group @@ -41,4 +42,11 @@ data class NoteRelationEntities( val notes: List, val users: List, val files: List +) + +data class NoteDTOUnpacked( + val note: NoteDTO, + val notes: List, + val users: List, + val files: List ) \ No newline at end of file diff --git a/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/note/NoteDataSourceAdder.kt b/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/note/NoteDataSourceAdder.kt index 01aaec8842..8c79312b55 100644 --- a/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/note/NoteDataSourceAdder.kt +++ b/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/note/NoteDataSourceAdder.kt @@ -7,7 +7,7 @@ import net.pantasystem.milktea.data.converters.FilePropertyDTOEntityConverter import net.pantasystem.milktea.data.converters.NoteDTOEntityConverter import net.pantasystem.milktea.data.converters.TootDTOEntityConverter import net.pantasystem.milktea.data.converters.UserDTOEntityConverter -import net.pantasystem.milktea.data.infrastructure.NoteRelationEntities +import net.pantasystem.milktea.data.infrastructure.NoteDTOUnpacked import net.pantasystem.milktea.data.infrastructure.toEntities import net.pantasystem.milktea.model.account.Account import net.pantasystem.milktea.model.drive.FileProperty @@ -45,7 +45,7 @@ class NoteDataSourceAdder @Inject constructor( noteDTOs: List, skipExists: Boolean = false, instanceType: InstanceInfoType? = null - ): List { + ): List { val info = instanceType?.takeIf { it.uri == account.normalizedInstanceUri } ?: instanceInfoService.find(account.normalizedInstanceUri).getOrNull() @@ -53,11 +53,14 @@ class NoteDataSourceAdder @Inject constructor( it.toEntities( account, userDTOEntityConverter, - noteDTOEntityConverter, filePropertyDTOEntityConverter, info, ) - + } + val notes = entities.flatMap { + it.notes + } + entities.map { + it.note } if (skipExists) { userDataSource.addAll( @@ -70,11 +73,13 @@ class NoteDataSourceAdder @Inject constructor( logger.error("UserDataSourceへの追加に失敗", it) } noteDataSource.addAll( - entities.flatMap { - it.notes - }.filterNot { - noteDataSource.exists(it.id) - } + noteDTOEntityConverter.convertAll( + account, + notes.filterNot { + noteDataSource.exists(Note.Id(account.accountId, it.id)) + }, + info, + ) ).onFailure { logger.error("NoteDataSourceへの追加に失敗", it) } @@ -93,9 +98,11 @@ class NoteDataSourceAdder @Inject constructor( }).onFailure { logger.error("UserDataSourceへの追加に失敗", it) } - noteDataSource.addAll(entities.flatMap { - it.notes - }).onFailure { + noteDataSource.addAll(noteDTOEntityConverter.convertAll( + account, + notes, + info, + )).onFailure { logger.error("NoteDataSourceへの追加に失敗", it) } filePropertyDataSource.addAll(entities.flatMap { @@ -105,7 +112,7 @@ class NoteDataSourceAdder @Inject constructor( } } return entities.map { - it.note + Note.Id(account.accountId, it.note.id) } } @@ -122,10 +129,10 @@ class NoteDataSourceAdder @Inject constructor( noteDTO.toEntities( account, userDTOEntityConverter, - noteDTOEntityConverter, filePropertyDTOEntityConverter, info, ) + val willReturnNote = noteDTOEntityConverter.convert(account, entities.note) if (skipExists) { userDataSource.addAll( entities.users.filterNot { @@ -135,14 +142,17 @@ class NoteDataSourceAdder @Inject constructor( logger.error("UserDataSourceへの追加に失敗", it) } noteDataSource.addAll( - entities.notes.filterNot { - noteDataSource.exists(it.id) - } + noteDTOEntityConverter.convertAll( + account, + entities.notes.filterNot { + noteDataSource.exists(Note.Id(account.accountId, it.id)) + } + ) ).onFailure { logger.error("NoteDataSourceへの追加に失敗", it) } - if (!noteDataSource.exists(entities.note.id)) { - noteDataSource.add(entities.note).onFailure { + if (!noteDataSource.exists(Note.Id(account.accountId, entities.note.id))) { + noteDataSource.add(willReturnNote).onFailure { logger.error("NoteDataSourceへの追加に失敗", it) } } @@ -157,7 +167,10 @@ class NoteDataSourceAdder @Inject constructor( userDataSource.addAll(entities.users).onFailure { logger.error("UserDataSourceへの追加に失敗", it) } - noteDataSource.addAll(entities.notes).onFailure { + noteDataSource.addAll(noteDTOEntityConverter.convertAll( + account, + entities.notes + )).onFailure { logger.error("NoteDataSourceへの追加に失敗", it) } filePropertyDataSource.addAll(entities.files).onFailure { @@ -165,7 +178,7 @@ class NoteDataSourceAdder @Inject constructor( } } - return entities.note + return willReturnNote } suspend fun addTootStatusDtoIntoDataSource( @@ -223,10 +236,9 @@ class NoteDataSourceAdder @Inject constructor( suspend fun NoteDTO.toEntities( account: Account, userDTOEntityConverter: UserDTOEntityConverter, - noteDTOEntityConverter: NoteDTOEntityConverter, filePropertyDTOEntityConverter: FilePropertyDTOEntityConverter, instanceType: InstanceInfoType?, -): NoteRelationEntities { +): NoteDTOUnpacked { val dtoList = mutableListOf() dtoList.add(this) @@ -239,9 +251,8 @@ suspend fun NoteDTO.toEntities( dtoList.add(reNote!!) } - val note = noteDTOEntityConverter.convert(account, this, instanceType) val users = mutableListOf() - val notes = mutableListOf() + val notes = mutableListOf() val files = mutableListOf() pickEntities( @@ -250,12 +261,11 @@ suspend fun NoteDTO.toEntities( users, files, userDTOEntityConverter, - noteDTOEntityConverter, filePropertyDTOEntityConverter, instanceType, ) - return NoteRelationEntities( - note = note, + return NoteDTOUnpacked( + note = this, notes = notes, users = users, files = files @@ -264,19 +274,16 @@ suspend fun NoteDTO.toEntities( private suspend fun NoteDTO.pickEntities( account: Account, - notes: MutableList, + notes: MutableList, users: MutableList, files: MutableList, userDTOEntityConverter: UserDTOEntityConverter, - noteDTOEntityConverter: NoteDTOEntityConverter, filePropertyDTOEntityConverter: FilePropertyDTOEntityConverter, instanceType: InstanceInfoType?, ) { val (note, user) = this.toNoteAndUser( account, userDTOEntityConverter, - noteDTOEntityConverter, - instanceType, ) notes.add(note) users.add(user) @@ -292,7 +299,6 @@ private suspend fun NoteDTO.pickEntities( users, files, userDTOEntityConverter, - noteDTOEntityConverter, filePropertyDTOEntityConverter, instanceType, ) @@ -305,7 +311,6 @@ private suspend fun NoteDTO.pickEntities( users, files, userDTOEntityConverter, - noteDTOEntityConverter, filePropertyDTOEntityConverter, instanceType, ) @@ -315,11 +320,8 @@ private suspend fun NoteDTO.pickEntities( suspend fun NoteDTO.toNoteAndUser( account: Account, userDTOEntityConverter: UserDTOEntityConverter, - noteDTOEntityConverter: NoteDTOEntityConverter, - instanceType: InstanceInfoType?, -): Pair { - val note = noteDTOEntityConverter.convert(account, this, instanceType) +): Pair { val user = userDTOEntityConverter.convert(account, user, false) - return note to user + return this to user } diff --git a/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/note/TimelinePagingStoreImpl.kt b/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/note/TimelinePagingStoreImpl.kt index 43ea1878cb..33bc411803 100644 --- a/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/note/TimelinePagingStoreImpl.kt +++ b/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/note/TimelinePagingStoreImpl.kt @@ -110,9 +110,7 @@ internal class TimelinePagingStoreImpl( it.promotionId == null || it.tmpFeaturedId == null }, instanceType = info - ).map { - it.id - } + ) } override fun getState(): PageableState> { From 72f101a8e044960385a518447cafb3d21cd26b00 Mon Sep 17 00:00:00 2001 From: Yuichiro Kinoshita Date: Sat, 28 Oct 2023 10:16:23 +0900 Subject: [PATCH 04/10] =?UTF-8?q?refactor:=20=E3=82=A4=E3=83=B3=E3=82=B9?= =?UTF-8?q?=E3=82=BF=E3=83=B3=E3=82=B9=E5=8C=96=E3=81=AE=E5=87=A6=E7=90=86?= =?UTF-8?q?=E3=82=92factory=E9=96=A2=E6=95=B0=E3=81=A8=E3=81=97=E3=81=A6?= =?UTF-8?q?=E5=88=87=E3=82=8A=E5=87=BA=E3=81=99=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/MediatorUserDataSource.kt | 31 +------------- .../data/infrastructure/user/db/UserRecord.kt | 40 ++++++++++++++++++- 2 files changed, 40 insertions(+), 31 deletions(-) diff --git a/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/user/MediatorUserDataSource.kt b/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/user/MediatorUserDataSource.kt index da1dcb9e1a..cc58310682 100644 --- a/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/user/MediatorUserDataSource.kt +++ b/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/user/MediatorUserDataSource.kt @@ -147,44 +147,17 @@ class MediatorUserDataSource @Inject constructor( if (user is User.Detail) { userDao.insert( - UserInfoStateRecord( - bannerUrl = user.info.bannerUrl, - - isLocked = user.info.isLocked, - - description = user.info.description, - followersCount = user.info.followersCount, - followingCount = user.info.followingCount, - - hostLower = user.info.hostLower, - notesCount = user.info.notesCount, - url = user.info.url, - userId = dbId, - birthday = user.info.birthday, - createdAt = user.info.createdAt, - updatedAt = user.info.updatedAt, - publicReactions = user.info.isPublicReactions - ) + UserInfoStateRecord.from(dbId, user.info) ) when (val related = user.related) { null -> {} else -> { userDao.insert( - UserRelatedStateRecord( - isMuting = related.isMuting, - isBlocking = related.isBlocking, - isFollower = related.isFollower, - isFollowing = related.isFollowing, - hasPendingFollowRequestToYou = related.hasPendingFollowRequestToYou, - hasPendingFollowRequestFromYou = related.hasPendingFollowRequestFromYou, - isNotify = related.isNotify, - userId = dbId, - ) + UserRelatedStateRecord.from(dbId, related) ) } } - // NOTE: 更新の必要性を判定 if ((record?.toModel() as? User.Detail?)?.info?.pinnedNoteIds?.toSet() != user.info.pinnedNoteIds?.toSet()) { // NOTE: 更新系の場合は一度削除する diff --git a/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/user/db/UserRecord.kt b/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/user/db/UserRecord.kt index 8d7aa692e3..08b4346ff5 100644 --- a/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/user/db/UserRecord.kt +++ b/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/user/db/UserRecord.kt @@ -145,7 +145,27 @@ data class UserInfoStateRecord( @ColumnInfo(name = "userId") @PrimaryKey(autoGenerate = false) val userId: Long -) +) { + companion object { + fun from(dbId: Long, info: User.Info): UserInfoStateRecord { + return UserInfoStateRecord( + bannerUrl = info.bannerUrl, + isLocked = info.isLocked, + description = info.description, + followersCount = info.followersCount, + followingCount = info.followingCount, + hostLower = info.hostLower, + notesCount = info.notesCount, + url = info.url, + userId = dbId, + birthday = info.birthday, + createdAt = info.createdAt, + updatedAt = info.updatedAt, + publicReactions = info.isPublicReactions + ) + } + } +} @Entity( tableName = "user_related_state", @@ -186,7 +206,23 @@ data class UserRelatedStateRecord( @ColumnInfo(name = "userId") @PrimaryKey(autoGenerate = false) val userId: Long -) +) { + + companion object { + fun from(dbId: Long, related: User.Related): UserRelatedStateRecord { + return UserRelatedStateRecord( + isMuting = related.isMuting, + isBlocking = related.isBlocking, + isFollower = related.isFollower, + isFollowing = related.isFollowing, + hasPendingFollowRequestToYou = related.hasPendingFollowRequestToYou, + hasPendingFollowRequestFromYou = related.hasPendingFollowRequestFromYou, + isNotify = related.isNotify, + userId = dbId, + ) + } + } +} @Entity( tableName = "user_detailed_state", From bfde11fe4c2c359a70363c8a0043d888e7edc5d5 Mon Sep 17 00:00:00 2001 From: Yuichiro Kinoshita Date: Sat, 28 Oct 2023 10:21:13 +0900 Subject: [PATCH 05/10] =?UTF-8?q?refactor:=20=E3=82=A4=E3=83=B3=E3=82=B9?= =?UTF-8?q?=E3=82=BF=E3=83=B3=E3=82=B9=E5=8C=96=E3=81=AE=E5=87=A6=E7=90=86?= =?UTF-8?q?=E3=82=92factory=E9=96=A2=E6=95=B0=E3=81=A8=E3=81=97=E3=81=A6?= =?UTF-8?q?=E5=88=87=E3=82=8A=E5=87=BA=E3=81=99=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/MediatorUserDataSource.kt | 19 ++---------- .../data/infrastructure/user/db/UserRecord.kt | 30 ++++++++++++++++++- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/user/MediatorUserDataSource.kt b/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/user/MediatorUserDataSource.kt index cc58310682..b860064029 100644 --- a/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/user/MediatorUserDataSource.kt +++ b/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/user/MediatorUserDataSource.kt @@ -133,14 +133,7 @@ class MediatorUserDataSource @Inject constructor( } userDao.insertEmojis( user.emojis.map { - UserEmojiRecord( - userId = dbId, - name = it.name, - uri = it.uri, - url = it.url, - aspectRatio = it.aspectRatio, - cachePath = it.cachePath - ) + UserEmojiRecord.from(dbId, it) } ) } @@ -187,15 +180,7 @@ class MediatorUserDataSource @Inject constructor( null -> Unit else -> { userDao.insertUserInstanceInfo( - UserInstanceInfoRecord( - faviconUrl = instance.faviconUrl, - iconUrl = instance.iconUrl, - name = instance.name, - softwareVersion = instance.softwareVersion, - softwareName = instance.softwareName, - themeColor = instance.themeColor, - userId = dbId - ) + UserInstanceInfoRecord.from(dbId, instance) ) } } diff --git a/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/user/db/UserRecord.kt b/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/user/db/UserRecord.kt index 08b4346ff5..92262ee453 100644 --- a/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/user/db/UserRecord.kt +++ b/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/user/db/UserRecord.kt @@ -338,6 +338,20 @@ data class UserEmojiRecord( @ColumnInfo(name = "id") @PrimaryKey(autoGenerate = true) val id: Long = 0L, ) { + + companion object { + fun from(dbId: Long, mode: CustomEmoji): UserEmojiRecord { + return UserEmojiRecord( + name = mode.name, + url = mode.url, + uri = mode.uri, + aspectRatio = mode.aspectRatio, + cachePath = mode.cachePath, + userId = dbId, + ) + } + } + fun toModel(): CustomEmoji { return CustomEmoji( name = name, @@ -405,7 +419,21 @@ data class UserInstanceInfoRecord( @ColumnInfo(name = "userId") @PrimaryKey(autoGenerate = false) val userId: Long -) +) { + companion object { + fun from(dbId: Long, instance: User.InstanceInfo): UserInstanceInfoRecord { + return UserInstanceInfoRecord( + faviconUrl = instance.faviconUrl, + iconUrl = instance.iconUrl, + name = instance.name, + softwareVersion = instance.softwareVersion, + softwareName = instance.softwareName, + themeColor = instance.themeColor, + userId = dbId + ) + } + } +} @Entity( tableName = "pinned_note_id", From 5686089449488c8b30a338b7a8324ff8da8b69cf Mon Sep 17 00:00:00 2001 From: Yuichiro Kinoshita Date: Sat, 28 Oct 2023 10:27:34 +0900 Subject: [PATCH 06/10] =?UTF-8?q?refactor:=20=E3=82=A4=E3=83=B3=E3=82=B9?= =?UTF-8?q?=E3=82=BF=E3=83=B3=E3=82=B9=E5=8C=96=E3=81=AE=E5=87=A6=E7=90=86?= =?UTF-8?q?=E3=82=92factory=E9=96=A2=E6=95=B0=E3=81=A8=E3=81=97=E3=81=A6?= =?UTF-8?q?=E5=88=87=E3=82=8A=E5=87=BA=E3=81=99=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/MediatorUserDataSource.kt | 80 +++++++++++-------- 1 file changed, 46 insertions(+), 34 deletions(-) diff --git a/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/user/MediatorUserDataSource.kt b/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/user/MediatorUserDataSource.kt index b860064029..3fcb229940 100644 --- a/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/user/MediatorUserDataSource.kt +++ b/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/user/MediatorUserDataSource.kt @@ -23,6 +23,7 @@ import net.pantasystem.milktea.data.infrastructure.user.db.UserInfoStateRecord import net.pantasystem.milktea.data.infrastructure.user.db.UserInstanceInfoRecord import net.pantasystem.milktea.data.infrastructure.user.db.UserProfileFieldRecord import net.pantasystem.milktea.data.infrastructure.user.db.UserRecord +import net.pantasystem.milktea.data.infrastructure.user.db.UserRelated import net.pantasystem.milktea.data.infrastructure.user.db.UserRelatedStateRecord import net.pantasystem.milktea.data.infrastructure.user.db.isEqualToModels import net.pantasystem.milktea.model.AddResult @@ -126,17 +127,7 @@ class MediatorUserDataSource @Inject constructor( // NOTE: 新たに追加される予定のオブジェクトと既にキャッシュしているオブジェクトの絵文字リストを比較している // NOTE: 比較した上で同一でなければキャッシュの更新処理を行う - if (!record?.emojis.isEqualToModels(user.emojis)) { - // NOTE: 既にキャッシュに存在していた場合一度全て剥がす - if (record != null) { - userDao.detachAllUserEmojis(dbId) - } - userDao.insertEmojis( - user.emojis.map { - UserEmojiRecord.from(dbId, it) - } - ) - } + replaceEmojisIfNeed(dbId, user, record) if (user is User.Detail) { userDao.insert( @@ -152,29 +143,8 @@ class MediatorUserDataSource @Inject constructor( } // NOTE: 更新の必要性を判定 - if ((record?.toModel() as? User.Detail?)?.info?.pinnedNoteIds?.toSet() != user.info.pinnedNoteIds?.toSet()) { - // NOTE: 更新系の場合は一度削除する - if (record != null) { - userDao.detachAllPinnedNoteIds(dbId) - } - - if (!user.info.pinnedNoteIds.isNullOrEmpty()) { - userDao.insertPinnedNoteIds(user.info.pinnedNoteIds!!.map { - PinnedNoteIdRecord(it.noteId, userId = dbId, 0L) - }) - } - - } - if ((record?.toModel() as? User.Detail?)?.info?.fields?.toSet() != user.info.fields.toSet()) { - if (record != null) { - userDao.detachUserFields(dbId) - } - if (user.info.fields.isNotEmpty()) { - userDao.insertUserProfileFields(user.info.fields.map { - UserProfileFieldRecord(it.name, it.value, dbId) - }) - } - } + replacePinnedNoteIdsIfNeed(dbId, user, record) + replaceFieldsIfNeed(dbId, user, record) } when (val instance = user.instance) { null -> Unit @@ -326,4 +296,46 @@ class MediatorUserDataSource @Inject constructor( } } + private suspend fun replaceEmojisIfNeed(dbId: Long, user: User, record: UserRelated?) { + if (!record?.emojis.isEqualToModels(user.emojis)) { + // NOTE: 既にキャッシュに存在していた場合一度全て剥がす + if (record != null) { + userDao.detachAllUserEmojis(dbId) + } + userDao.insertEmojis( + user.emojis.map { + UserEmojiRecord.from(dbId, it) + } + ) + } + } + + private suspend fun replacePinnedNoteIdsIfNeed(dbId: Long, user: User.Detail, record: UserRelated?) { + if ((record?.toModel() as? User.Detail?)?.info?.pinnedNoteIds?.toSet() != user.info.pinnedNoteIds?.toSet()) { + // NOTE: 更新系の場合は一度削除する + if (record != null) { + userDao.detachAllPinnedNoteIds(dbId) + } + + if (!user.info.pinnedNoteIds.isNullOrEmpty()) { + userDao.insertPinnedNoteIds(user.info.pinnedNoteIds!!.map { + PinnedNoteIdRecord(it.noteId, userId = dbId, 0L) + }) + } + + } + } + + private suspend fun replaceFieldsIfNeed(dbId: Long, user: User.Detail, record: UserRelated?) { + if ((record?.toModel() as? User.Detail?)?.info?.fields?.toSet() != user.info.fields.toSet()) { + if (record != null) { + userDao.detachUserFields(dbId) + } + if (user.info.fields.isNotEmpty()) { + userDao.insertUserProfileFields(user.info.fields.map { + UserProfileFieldRecord(it.name, it.value, dbId) + }) + } + } + } } \ No newline at end of file From 580834ada8c4bc2fe451c588ec844e851b533ed4 Mon Sep 17 00:00:00 2001 From: Yuichiro Kinoshita Date: Sat, 28 Oct 2023 10:43:38 +0900 Subject: [PATCH 07/10] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E3=81=AE?= =?UTF-8?q?=E5=BF=85=E8=A6=81=E6=80=A7=E3=81=AE=E6=9C=89=E7=84=A1=E3=82=92?= =?UTF-8?q?=E3=83=81=E3=82=A7=E3=83=83=E3=82=AF=E3=81=99=E3=82=8B=E3=83=AD?= =?UTF-8?q?=E3=82=B8=E3=83=83=E3=82=AF=E3=82=92=E5=BC=B7=E5=8C=96=E3=81=97?= =?UTF-8?q?=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/MediatorUserDataSource.kt | 24 +++++++++--- .../data/infrastructure/user/db/UserRecord.kt | 37 +++++++++++++++++++ 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/user/MediatorUserDataSource.kt b/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/user/MediatorUserDataSource.kt index 3fcb229940..e5b830cdb6 100644 --- a/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/user/MediatorUserDataSource.kt +++ b/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/user/MediatorUserDataSource.kt @@ -117,6 +117,16 @@ class MediatorUserDataSource @Inject constructor( val newRecord = UserRecord.from(user) val record = userDao.get(user.id.accountId, user.id.id) + val recordToDetailed = (record?.toModel() as? User.Detail?) + val recordToSimpled = record?.toSimpleModel() + if (user == recordToDetailed) { + return@withContext AddResult.Canceled + } + + if (user is User.Simple && recordToSimpled == user) { + return@withContext AddResult.Canceled + } + val result = if (record == null) AddResult.Created else AddResult.Updated val dbId = if (record == null) { userDao.insert(newRecord) @@ -143,8 +153,8 @@ class MediatorUserDataSource @Inject constructor( } // NOTE: 更新の必要性を判定 - replacePinnedNoteIdsIfNeed(dbId, user, record) - replaceFieldsIfNeed(dbId, user, record) + replacePinnedNoteIdsIfNeed(dbId, user, record, recordToDetailed) + replaceFieldsIfNeed(dbId, user, record, recordToDetailed) } when (val instance = user.instance) { null -> Unit @@ -310,8 +320,9 @@ class MediatorUserDataSource @Inject constructor( } } - private suspend fun replacePinnedNoteIdsIfNeed(dbId: Long, user: User.Detail, record: UserRelated?) { - if ((record?.toModel() as? User.Detail?)?.info?.pinnedNoteIds?.toSet() != user.info.pinnedNoteIds?.toSet()) { + 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) { userDao.detachAllPinnedNoteIds(dbId) @@ -326,8 +337,9 @@ class MediatorUserDataSource @Inject constructor( } } - private suspend fun replaceFieldsIfNeed(dbId: Long, user: User.Detail, record: UserRelated?) { - if ((record?.toModel() as? User.Detail?)?.info?.fields?.toSet() != user.info.fields.toSet()) { + 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) } diff --git a/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/user/db/UserRecord.kt b/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/user/db/UserRecord.kt index 92262ee453..363dc0a205 100644 --- a/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/user/db/UserRecord.kt +++ b/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/user/db/UserRecord.kt @@ -724,4 +724,41 @@ data class UserRelated( ) } } + + fun toSimpleModel(): User.Simple { + val instanceInfo = instance?.let { + User.InstanceInfo( + faviconUrl = it.faviconUrl, + iconUrl = it.iconUrl, + name = it.name, + softwareName = it.softwareName, + softwareVersion = it.softwareVersion, + themeColor = it.themeColor + ) + } + return User.Simple( + id = User.Id( + user.accountId, + user.serverId, + ), + userName = user.userName, + avatarUrl = user.avatarUrl, + emojis = emojis.map { + it.toModel() + }, + host = user.host, + isBot = user.isBot, + isCat = user.isCat, + isSameHost = user.isSameHost, + name = user.name, + nickname = user.nickname?.let { + UserNickname( + id = UserNickname.Id(user.userName, user.host), + name = user.nickname + ) + }, + instance = instanceInfo, + avatarBlurhash = user.avatarBlurhash, + ) + } } \ No newline at end of file From 2d7c3652de26f1b1d408e677dc938d0aff2f49e9 Mon Sep 17 00:00:00 2001 From: Yuichiro Kinoshita Date: Sat, 28 Oct 2023 10:51:39 +0900 Subject: [PATCH 08/10] =?UTF-8?q?feat:=20addAll=E6=99=82=E3=81=AF=E4=B8=80?= =?UTF-8?q?=E6=8B=AC=E3=81=A7insert=E3=81=99=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../note/impl/ObjectBoxNoteDataSource.kt | 55 +++++++++++++------ 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/note/impl/ObjectBoxNoteDataSource.kt b/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/note/impl/ObjectBoxNoteDataSource.kt index 322c0d10e7..b9e59b3c1f 100644 --- a/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/note/impl/ObjectBoxNoteDataSource.kt +++ b/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/note/impl/ObjectBoxNoteDataSource.kt @@ -68,7 +68,7 @@ class ObjectBoxNoteDataSource @Inject constructor( noteBox.query().inValues( NoteRecord_.accountIdAndNoteId, ids.toTypedArray(), - QueryBuilder.StringOrder.CASE_SENSITIVE + QueryBuilder.StringOrder.CASE_INSENSITIVE ).build().find().map { it.toModel() } @@ -83,7 +83,7 @@ class ObjectBoxNoteDataSource @Inject constructor( noteBox.query().equal( NoteRecord_.accountIdAndNoteId, NoteRecord.generateAccountAndNoteId(noteId), - QueryBuilder.StringOrder.CASE_SENSITIVE + QueryBuilder.StringOrder.CASE_INSENSITIVE ).build().findFirst()?.toModel() ?: throw NoteNotFoundException(noteId) } } @@ -96,7 +96,7 @@ class ObjectBoxNoteDataSource @Inject constructor( noteBox.query().equal( NoteRecord_.accountIdAndNoteId, NoteRecord.generateAccountAndNoteId(noteId), - QueryBuilder.StringOrder.CASE_SENSITIVE + QueryBuilder.StringOrder.CASE_INSENSITIVE ).build().findFirst()?.toModel() } when(note) { @@ -110,7 +110,7 @@ class ObjectBoxNoteDataSource @Inject constructor( noteBox.query().equal( NoteRecord_.replyId, id.noteId, - QueryBuilder.StringOrder.CASE_SENSITIVE, + QueryBuilder.StringOrder.CASE_INSENSITIVE, ).and().equal( NoteRecord_.accountId, id.accountId @@ -124,7 +124,7 @@ class ObjectBoxNoteDataSource @Inject constructor( return noteBox.query().equal( NoteRecord_.accountIdAndNoteId, NoteRecord.generateAccountAndNoteId(noteId), - QueryBuilder.StringOrder.CASE_SENSITIVE + QueryBuilder.StringOrder.CASE_INSENSITIVE ).build().findFirst()?.let { return true } ?: false @@ -136,7 +136,7 @@ class ObjectBoxNoteDataSource @Inject constructor( noteBox.query().equal( NoteRecord_.accountIdAndNoteId, NoteRecord.generateAccountAndNoteId(noteId), - QueryBuilder.StringOrder.CASE_SENSITIVE + QueryBuilder.StringOrder.CASE_INSENSITIVE ).build().remove() }?.let { it > 0 @@ -158,7 +158,7 @@ class ObjectBoxNoteDataSource @Inject constructor( val exists = noteBox.query().equal( NoteRecord_.accountIdAndNoteId, NoteRecord.generateAccountAndNoteId(note.id), - QueryBuilder.StringOrder.CASE_SENSITIVE + QueryBuilder.StringOrder.CASE_INSENSITIVE ).build().findFirst() if (exists == null) { noteBox.put(NoteRecord.from(note)) @@ -185,18 +185,41 @@ class ObjectBoxNoteDataSource @Inject constructor( override suspend fun addAll(notes: List): Result> = runCancellableCatching { - notes.map { - add(it) - }.map { - it.getOrElse { AddResult.Canceled } - } + withContext(ioDispatcher) { + boxStore.awaitCallInTx { + val existsNotes = noteBox.query().inValues( + NoteRecord_.accountIdAndNoteId, + notes.map { + NoteRecord.generateAccountAndNoteId(it.id) + }.toTypedArray(), + QueryBuilder.StringOrder.CASE_INSENSITIVE + ).build().find().associateBy { + it.noteId + } + val willSave = notes.map { + val exists = existsNotes[it.id.noteId] + if (exists == null) { + NoteRecord.from(it) to AddResult.Created + } else { + exists.applyModel(it) + exists to AddResult.Updated + } + } + noteBox.put(willSave.map { + it.first + }) + willSave.map { + it.second + } + } + }?: emptyList() } override suspend fun deleteByUserId(userId: User.Id): Result = runCancellableCatching { withContext(ioDispatcher) { boxStore.awaitCallInTx { noteBox.query() - .equal(NoteRecord_.userId, userId.id, QueryBuilder.StringOrder.CASE_SENSITIVE) + .equal(NoteRecord_.userId, userId.id, QueryBuilder.StringOrder.CASE_INSENSITIVE) .and().equal(NoteRecord_.accountId, userId.accountId) .build().remove().toInt() } ?: 0 @@ -220,7 +243,7 @@ class ObjectBoxNoteDataSource @Inject constructor( return noteBox.query().inValues( NoteRecord_.accountIdAndNoteId, ids.toTypedArray(), - QueryBuilder.StringOrder.CASE_SENSITIVE + QueryBuilder.StringOrder.CASE_INSENSITIVE ).build().subscribe().toFlow().flowOn(ioDispatcher).map { list -> list.mapNotNull { it?.toModel() @@ -233,7 +256,7 @@ class ObjectBoxNoteDataSource @Inject constructor( return noteBox.query().equal( NoteRecord_.accountIdAndNoteId, NoteRecord.generateAccountAndNoteId(noteId), - QueryBuilder.StringOrder.CASE_SENSITIVE + QueryBuilder.StringOrder.CASE_INSENSITIVE ).build().subscribe().toFlow().flowOn(ioDispatcher).map { it.firstOrNull()?.toModel() }.flowOn(defaultDispatcher).catch { @@ -321,7 +344,7 @@ class ObjectBoxNoteDataSource @Inject constructor( NoteRecord_.accountIdAndNoteId, noteIds.map { NoteRecord.generateAccountAndNoteId(it) }.toTypedArray(), - QueryBuilder.StringOrder.CASE_SENSITIVE + QueryBuilder.StringOrder.CASE_INSENSITIVE ).build().find() } } \ No newline at end of file From 40994d1838752c75c1f40e15dda9468f1bb05912 Mon Sep 17 00:00:00 2001 From: Yuichiro Kinoshita Date: Sat, 28 Oct 2023 10:57:54 +0900 Subject: [PATCH 09/10] =?UTF-8?q?feat:=20conflict=E6=99=82=E3=81=AFreplace?= =?UTF-8?q?=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/data/objectbox-models/default.json | 2 +- modules/data/objectbox-models/default.json.bak | 7 ++++++- .../milktea/data/infrastructure/note/impl/db/NoteRecord.kt | 3 ++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/data/objectbox-models/default.json b/modules/data/objectbox-models/default.json index d87043cbb9..3f0c988f4e 100644 --- a/modules/data/objectbox-models/default.json +++ b/modules/data/objectbox-models/default.json @@ -33,7 +33,7 @@ "name": "accountIdAndNoteId", "indexId": "1:7288350540838608646", "type": 9, - "flags": 2080 + "flags": 34848 }, { "id": "5:7710661194467523389", diff --git a/modules/data/objectbox-models/default.json.bak b/modules/data/objectbox-models/default.json.bak index 1b715a258b..d87043cbb9 100644 --- a/modules/data/objectbox-models/default.json.bak +++ b/modules/data/objectbox-models/default.json.bak @@ -5,7 +5,7 @@ "entities": [ { "id": "1:4355718382021751829", - "lastPropertyId": "54:1696546822899785376", + "lastPropertyId": "55:68607803971520561", "name": "NoteRecord", "properties": [ { @@ -286,6 +286,11 @@ "id": "54:1696546822899785376", "name": "customEmojiUrlAndCachePathMap", "type": 13 + }, + { + "id": "55:68607803971520561", + "name": "misskeyIsRequireNyaize", + "type": 1 } ], "relations": [] diff --git a/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/note/impl/db/NoteRecord.kt b/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/note/impl/db/NoteRecord.kt index 5c007e9832..e119c5f358 100644 --- a/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/note/impl/db/NoteRecord.kt +++ b/modules/data/src/main/java/net/pantasystem/milktea/data/infrastructure/note/impl/db/NoteRecord.kt @@ -1,5 +1,6 @@ package net.pantasystem.milktea.data.infrastructure.note.impl.db +import io.objectbox.annotation.ConflictStrategy import io.objectbox.annotation.Entity import io.objectbox.annotation.Id import io.objectbox.annotation.Index @@ -26,7 +27,7 @@ data class NoteRecord( @Index var noteId: String = "", - @Unique + @Unique(onConflict = ConflictStrategy.REPLACE) @Index var accountIdAndNoteId: String = "", From bd9f6e314a639108d8792763ab3083952e18a6c9 Mon Sep 17 00:00:00 2001 From: Yuichiro Kinoshita Date: Sat, 28 Oct 2023 11:20:32 +0900 Subject: [PATCH 10/10] =?UTF-8?q?fix:=20=E3=83=87=E3=83=95=E3=82=A9?= =?UTF-8?q?=E3=83=AB=E3=83=88=E5=80=A4=E5=8F=96=E5=BE=97=E3=81=AE=E5=87=A6?= =?UTF-8?q?=E7=90=86=E3=81=AE=E5=AE=9F=E8=A3=85=E3=81=AE=E8=AA=A4=E3=82=8A?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../milktea/data/converters/NoteDTOEntityConverter.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/data/src/main/java/net/pantasystem/milktea/data/converters/NoteDTOEntityConverter.kt b/modules/data/src/main/java/net/pantasystem/milktea/data/converters/NoteDTOEntityConverter.kt index ba192e4720..cdf797f13b 100644 --- a/modules/data/src/main/java/net/pantasystem/milktea/data/converters/NoteDTOEntityConverter.kt +++ b/modules/data/src/main/java/net/pantasystem/milktea/data/converters/NoteDTOEntityConverter.kt @@ -81,10 +81,11 @@ class NoteDTOEntityConverter @Inject constructor( }).associateBy { it.sourceUrl } + val info = instanceInfoType ?: instanceInfoService.find(account.normalizedInstanceUri).getOrNull() return convert( account = account, noteDTO = noteDTO, - instanceInfoType = instanceInfoType, + instanceInfoType = info, aspects = aspects, fileCaches = fileCaches )