0

领域版本 - 10.4.0

这是我在项目中使用的主要领域模型类。所有这些模型都具有最多 1-2 级嵌套的嵌入式对象或领域模型。

大约 10k 个条目

open class MemberRO(
    @PrimaryKey
    var uid: String = "",
    var id: String = "",
    var name: String = "",
    var imageUrl: String = "",
    var state: Int = 0,
    var removeState: Int? = null,
    var customIntroText: String? = null,
    var customClickText: String? = null,
    var customTitle: String? = null,
    var chatroomId: Int? = null,
    var communityId: Int? = null,
    var isOwner: Boolean? = null,
    var community: CommunityRO? = null,
    var chatroom: CollabcardRO? = null
) : RealmObject()

大约 1k 个条目

open class CommunityRO(
    @PrimaryKey
    var id: Int = 0,
    @Required
    var name: String = "",
    var membersCount: Int = -1,
    var pendingMembersCount: Int = -1,
    var collabcardsUnseen: Int = -1,
    var imageURL: String? = null,
    var purpose: String? = null,
    var about: String? = null,
    var updatedAt: String? = null,
    var memberState: Int? = null,
    var type: Int? = null,
    var subType: Int? = null,
    var clickState: Int? = null,
    var actions: RealmList<CommunityActionRO> = RealmList(),
    var pendingChatRoomCount: Int = 0,
    var openReportsCount: Int = 0,
    var memberRightStates: RealmList<Int> = RealmList(),
    var orderTime: Long? = null,
    var pinnedSubTitle: String? = null,
    var canShowPinnedBanner: Boolean? = null,
    var conversations: RealmList<CollabcardAnswerRO>? = null,
    var chatrooms: RealmList<CollabcardRO>? = null,
    var relationshipNeeded: Boolean = true
) : RealmObject()

大约 100k-200k 条目

open class CollabcardAnswerRO(
    @PrimaryKey
    var id: String = "",
    var chatroomId: Int = 0,
    var communityId: Int = 0,
    var member: MemberRO? = null,
    @Required
    var answer: String = "",
    var state: Int = 0,
    var createdEpoch: Long = 0L,
    var createdAt: String? = null,
    var attachments: RealmList<AttachmentRO> = RealmList(),
    var lastSeen: Boolean = false,
    var link: LinkRO? = null,
    var date: String? = null,
    var isEdited: Boolean? = null,
    var preview: PreviewRO? = null,
    var replyConversationId: String? = null,
    var replyConversation: CollabcardAnswerRO? = null,
    var deletedBy: String? = null,
    var attachmentCount: Int? = null,
    var attachmentsUploaded: Boolean? = null,
    var uploadWorkerUUID: String? = null,
    var localSavedEpoch: Long = 0L,
    var temporaryId: String? = null,
    var reactions: RealmList<MessageReactionRO> = RealmList(),
    @LinkingObjects("conversations")
    val community: RealmResults<CommunityRO>? = null,
    @LinkingObjects("conversations")
    val chatroom: RealmResults<CollabcardRO>? = null
) : RealmObject()

大约 20,000 个条目

open class CollabcardRO(
    @PrimaryKey
    var id: Int = 0,
    var communityId: Int = 0,
    @Required
    var title: String = "",
    var state: Int? = null,
    var member: MemberRO? = null,
    var createdAt: String? = null,
    var answerText: String? = null,
    var attachments: RealmList<AttachmentRO> = RealmList(),
    var shareUrl: String? = null,
    var link: LinkRO? = null,
    var attachmentCount: Int? = null,
    var attachmentsUploaded: Boolean? = null,
    var type: Int? = null,
    var dateTime: Long? = null,
    var endDate: Long? = null,
    var polls: RealmList<PollRO> = RealmList(),
    var pollsCount: Int? = null,
    var attendingCount: Int? = null,
    var about: String? = null,
    var location: String? = null,
    var locationLat: Double? = null,
    var locationLong: Double? = null,
    var coHosts: RealmList<MemberRO> = RealmList(),
    var onlineLink: String? = null,
    var header: String? = null,
    var cardCreationTime: String? = null,
    var totalResponseCount: Int = 0,
    var multipleSelectNum: Int? = null,
    var multipleSelectState: Int? = null,
    var muteStatus: Boolean? = null,
    var followStatus: Boolean? = null,
    var creatorShareUrl: String? = null,
    var hasBeenNamed: Boolean? = null,
    var isGuest: Boolean? = null,
    var date: String? = null,
    var lastFiveUniqueMembers: RealmList<MemberRO> = RealmList(),
    var pollType: Int? = null,
    var pollTypeText: String? = null,
    var submitTypeText: String? = null,
    var expiryTime: Long? = null,
    var isAnonymous: Boolean? = null,
    var allowAddOption: Boolean? = null,
    var isTagged: Boolean? = null,
    var preview: PreviewRO? = null,
    var isPending: Boolean? = null,
    var chatroomExpiryTime: Long? = null,
    var deletedBy: String? = null,
    var isDraft: Boolean? = null,
    var updatedAt: Long? = null,
    var lastConversation: CollabcardAnswerRO? = null,
    var lastSeenConversationId: Int? = null,
    var lastSeenConversation: CollabcardAnswerRO? = null,
    var dateEpoch: Long? = null,
    var unseenCount: Int = 0,
    var relationshipNeeded: Boolean = true,
    var uploadWorkerUUID: String? = null,
    var draftConversation: String? = null,
    var isSecret: Boolean? = null,
    var secretChatRoomParticipants: RealmList<Int> = RealmList(),
    var secretChatRoomLeft: Boolean? = null,
    var conversations: RealmList<CollabcardAnswerRO>? = null,
    @LinkingObjects("chatrooms")
    val communities: RealmResults<CommunityRO>? = null
) : RealmObject()

读取速度非常快,并且由于反向关系,数据在 50 毫秒内被查询。但是写事务非常非常慢。

对于像下面这样一个非常简单的写事务,它需要 > 20 秒才能完成。

realm.executeTransactionAsync { bgRealm ->
    val conversation = bgRealm.where(CollabcardAnswerRO::class.java)
        .equalTo("id", "123").findFirst()
    conversation?.answer = "Hello"
}

我使用日志检查了事务,发现写入事务块在 < 50 毫秒内执行,但提交事务或调用事务的 onSuccess 方法发生在 > 20 秒内。

另外,我发现一件有趣的事情是,如果我通过在协程 IO 调度程序中调用 executeTransaction 而不使用异步来执行相同的写入事务,它会将写入事务加速到 5-10 秒。但是5-10秒还是不好。

另外,我尝试删除任何通知侦听器,因为差异检查需要时间,但这并没有太大帮助。另外,我的写事务没有被其他事务阻止,我已经确认了这一点。

4

0 回答 0