Sugar: defined extensions fo deleteOnCascade() methods, as they have to be called in a transaction

This commit is contained in:
Benoit Marty 2021-02-08 12:37:38 +01:00
parent 424035f56f
commit 30be440774
11 changed files with 67 additions and 68 deletions

View File

@ -30,11 +30,6 @@ internal open class CrossSigningInfoEntity(
companion object
fun deleteOnCascade() {
crossSigningKeys.clearWith { it.deleteOnCascade() }
deleteFromRealm()
}
fun getMasterKey() = crossSigningKeys.firstOrNull { it.usages.contains(KeyUsage.MASTER.value) }
fun setMasterKey(info: KeyInfoEntity?) {
@ -62,3 +57,8 @@ internal open class CrossSigningInfoEntity(
info?.let { crossSigningKeys.add(it) }
}
}
internal fun CrossSigningInfoEntity.deleteOnCascade() {
crossSigningKeys.clearWith { it.deleteOnCascade() }
deleteFromRealm()
}

View File

@ -46,9 +46,9 @@ internal open class DeviceInfoEntity(
val users: RealmResults<UserEntity>? = null
companion object
fun deleteOnCascade() {
trustLevelEntity?.deleteFromRealm()
deleteFromRealm()
}
}
internal fun DeviceInfoEntity.deleteOnCascade() {
trustLevelEntity?.deleteFromRealm()
deleteFromRealm()
}

View File

@ -29,10 +29,9 @@ internal open class KeyInfoEntity(
*/
var signatures: String? = null,
var trustLevelEntity: TrustLevelEntity? = null
) : RealmObject() {
) : RealmObject()
fun deleteOnCascade() {
trustLevelEntity?.deleteFromRealm()
deleteFromRealm()
}
internal fun KeyInfoEntity.deleteOnCascade() {
trustLevelEntity?.deleteFromRealm()
deleteFromRealm()
}

View File

@ -29,10 +29,10 @@ internal open class UserEntity(
) : RealmObject() {
companion object
fun deleteOnCascade() {
devices.clearWith { it.deleteOnCascade() }
crossSigningInfoEntity?.deleteOnCascade()
deleteFromRealm()
}
}
internal fun UserEntity.deleteOnCascade() {
devices.clearWith { it.deleteOnCascade() }
crossSigningInfoEntity?.deleteOnCascade()
deleteFromRealm()
}

View File

@ -44,13 +44,13 @@ internal open class ChunkEntity(@Index var prevToken: String? = null,
val room: RealmResults<RoomEntity>? = null
companion object
fun deleteOnCascade(deleteStateEvents: Boolean, canDeleteRoot: Boolean) {
assertIsManaged()
if (deleteStateEvents) {
stateEvents.deleteAllFromRealm()
}
timelineEvents.clearWith { it.deleteOnCascade(canDeleteRoot) }
deleteFromRealm()
}
}
internal fun ChunkEntity.deleteOnCascade(deleteStateEvents: Boolean, canDeleteRoot: Boolean) {
assertIsManaged()
if (deleteStateEvents) {
stateEvents.deleteAllFromRealm()
}
timelineEvents.clearWith { it.deleteOnCascade(canDeleteRoot) }
deleteFromRealm()
}

View File

@ -30,12 +30,12 @@ internal open class EventAnnotationsSummaryEntity(
) : RealmObject() {
companion object
fun deleteOnCascade() {
reactionsSummary.deleteAllFromRealm()
editSummary?.deleteFromRealm()
referencesSummaryEntity?.deleteFromRealm()
pollResponseSummary?.deleteFromRealm()
deleteFromRealm()
}
}
internal fun EventAnnotationsSummaryEntity.deleteOnCascade() {
reactionsSummary.deleteAllFromRealm()
editSummary?.deleteFromRealm()
referencesSummaryEntity?.deleteFromRealm()
pollResponseSummary?.deleteFromRealm()
deleteFromRealm()
}

View File

@ -39,9 +39,9 @@ internal open class PushRuleEntity(
val parent: RealmResults<PushRulesEntity>? = null
companion object
fun deleteOnCascade() {
conditions?.deleteAllFromRealm()
deleteFromRealm()
}
}
internal fun PushRuleEntity.deleteOnCascade() {
conditions?.deleteAllFromRealm()
deleteFromRealm()
}

View File

@ -35,9 +35,9 @@ internal open class PushRulesEntity(
}
companion object
fun deleteOnCascade() {
pushRules.clearWith { it.deleteOnCascade() }
deleteFromRealm()
}
}
internal fun PushRulesEntity.deleteOnCascade() {
pushRules.clearWith { it.deleteOnCascade() }
deleteFromRealm()
}

View File

@ -53,9 +53,9 @@ internal open class PusherEntity(
}
companion object
fun deleteOnCascade() {
data?.deleteFromRealm()
deleteFromRealm()
}
}
internal fun PusherEntity.deleteOnCascade() {
data?.deleteFromRealm()
deleteFromRealm()
}

View File

@ -33,9 +33,9 @@ internal open class ReadReceiptsSummaryEntity(
val timelineEvent: RealmResults<TimelineEventEntity>? = null
companion object
fun deleteOnCascade() {
readReceipts.deleteAllFromRealm()
deleteFromRealm()
}
}
internal fun ReadReceiptsSummaryEntity.deleteOnCascade() {
readReceipts.deleteAllFromRealm()
deleteFromRealm()
}

View File

@ -39,14 +39,14 @@ internal open class TimelineEventEntity(var localId: Long = 0,
val chunk: RealmResults<ChunkEntity>? = null
companion object
fun deleteOnCascade(canDeleteRoot: Boolean) {
assertIsManaged()
if (canDeleteRoot) {
root?.deleteFromRealm()
}
annotations?.deleteOnCascade()
readReceipts?.deleteOnCascade()
deleteFromRealm()
}
}
internal fun TimelineEventEntity.deleteOnCascade(canDeleteRoot: Boolean) {
assertIsManaged()
if (canDeleteRoot) {
root?.deleteFromRealm()
}
annotations?.deleteOnCascade()
readReceipts?.deleteOnCascade()
deleteFromRealm()
}