Removing non necessary fields that can be computed using other existing fields

This commit is contained in:
Maxime NATUREL 2023-01-17 16:59:07 +01:00
parent aa736e2bfc
commit 5473789577
3 changed files with 30 additions and 20 deletions

View file

@ -39,21 +39,11 @@ internal open class PollHistoryStatusEntity(
*/
var lastTimestampTargetBackwardMs: Long? = null,
/**
* Indicate whether all polls in a room have been synced for the current timestamp target in backward direction.
*/
var currentTimestampTargetBackwardReached: Boolean = false,
/**
* Indicate whether all polls in a room have been synced in backward direction.
*/
var isEndOfPollsBackward: Boolean = false,
/**
* Indicate whether at least one poll sync has been fully completed backward for the given room.
*/
var hasCompletedASyncBackward: Boolean = false,
/**
* Token of the end of the last synced chunk in backward direction.
*/
@ -66,4 +56,23 @@ internal open class PollHistoryStatusEntity(
) : RealmObject() {
companion object
/**
* Indicate whether at least one poll sync has been fully completed backward for the given room.
*/
val hasCompletedASyncBackward: Boolean
get() = lastTimestampTargetBackwardMs != null
/**
* Indicate whether all polls in a room have been synced for the current timestamp target in backward direction.
*/
val currentTimestampTargetBackwardReached: Boolean
get() = checkIfCurrentTimestampTargetBackwardIsReached()
private fun checkIfCurrentTimestampTargetBackwardIsReached(): Boolean {
val currentTarget = currentTimestampTargetBackwardMs
val lastTarget = lastTimestampTargetBackwardMs
// last timestamp target should be older or equal to the current target
return currentTarget != null && lastTarget != null && lastTarget <= currentTarget
}
}

View file

@ -36,7 +36,4 @@ internal open class PollResponseAggregatedSummaryEntity(
var sourceLocalEchoEvents: RealmList<String> = RealmList(),
// list of related event ids which are encrypted due to decryption failure
var encryptedRelatedEventIds: RealmList<String> = RealmList(),
) : RealmObject() {
companion object
}
) : RealmObject()

View file

@ -43,6 +43,10 @@ internal class DefaultLoadMorePollsTask @Inject constructor(
override suspend fun execute(params: LoadMorePollsTask.Params): LoadedPollsStatus {
updatePollHistoryStatus(params)
// TODO fetch events in a loop using current poll history status
// decrypt events and filter in only polls to store them in local
// parse the response to update poll history status
// unmock and check how it behaves when cancelling the process: it should resume where it was stopped
return LoadedPollsStatus(
canLoadMore = true,
nbLoadedDays = 10,
@ -52,15 +56,15 @@ internal class DefaultLoadMorePollsTask @Inject constructor(
private suspend fun updatePollHistoryStatus(params: LoadMorePollsTask.Params) {
monarchy.awaitTransaction { realm ->
val status = PollHistoryStatusEntity.getOrCreate(realm, params.roomId)
val currentTargetTimestamp = status.currentTimestampTargetBackwardMs
val loadingPeriodMs = MILLISECONDS_PER_DAY * params.loadingPeriodInDays
if (currentTargetTimestamp == null) {
val currentTargetTimestampMs = status.currentTimestampTargetBackwardMs
val lastTargetTimestampMs = status.lastTimestampTargetBackwardMs
val loadingPeriodMs: Long = MILLISECONDS_PER_DAY * params.loadingPeriodInDays.toLong()
if (currentTargetTimestampMs == null) {
// first load, compute the target timestamp
status.currentTimestampTargetBackwardMs = params.currentTimestampMs - loadingPeriodMs
} else if (status.currentTimestampTargetBackwardReached) {
} else if (lastTargetTimestampMs != null && status.currentTimestampTargetBackwardReached) {
// previous load has finished, update the target timestamp
status.currentTimestampTargetBackwardMs = currentTargetTimestamp - loadingPeriodMs
status.currentTimestampTargetBackwardReached = false
status.currentTimestampTargetBackwardMs = lastTargetTimestampMs - loadingPeriodMs
}
}
}