Yokan / rebuild
Course 1 8624561

HubResync.kt

composeApp/src/commonMain/kotlin/eu/friedcutlet/yokan/database/sync/HubResync.kt

implementation19 lines
1package eu.friedcutlet.yokan.database.sync23import eu.friedcutlet.yokan.database.DbSyncPreference45/**6 * The preference after the hub reported [epoch], plus the epoch whose older outbox operations7 * must be dropped (`null` keeps them). The first negotiation to epoch 1 is not a rollback.8 */9internal fun DbSyncPreference.hubResync(epoch: Int): Pair<DbSyncPreference, Int?> {10    val initialNegotiation = hubEpoch == 0 && !hubBootstrapComplete && epoch == 111    val rollback = !initialNegotiation && (hubEpoch > 0 || hubBootstrapComplete || epoch > 1)12    val dropBefore = epoch.takeIf { rollback && it > hubEpoch }13    val updated = copy(14        hubHead = 0,15        hubEpoch = maxOf(hubEpoch, epoch),16        hubRecoveryPending = hubRecoveryPending || dropBefore != null,17    )18    return updated to dropBefore19}20

Search chapters, reference and source filenames.