-
-
Notifications
You must be signed in to change notification settings - Fork 92
Sync on collection update #1240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sync on collection update #1240
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder how this behaves when the services are refreshed. Doesn't it enqueue a lot of syncs during service detection (whenever a collection is updated)?
My ideas (may or may not make sense):
- A delay of a few seconds between the collection change and the sync (like for the push registration) could at least reduce the number of synchronizations during service detection.
- Or maybe pause it somehow?
- Maybe separate callbacks for the actions we want to observe (update read-only, update sync flag)? Has advantages and disadvantages.
app/src/main/kotlin/at/bitfire/davdroid/sync/worker/SyncWorkerManager.kt
Outdated
Show resolved
Hide resolved
945029e
to
7f58df8
Compare
f9a0940
to
7d4bca1
Compare
Hm, because we're not sure about unwanted consequences (regarding service detection etc) Maybe we could the sync from the UI? So that not the DB Collection is observed, but instead when the user changes the read-only / sync flag in the UI, it waits a few seconds and then starts a sync? |
Sure, we should drop #1230 then though, since we don't want that feature anymore? |
I mean we could sync when they're (un)checked by the user in the UI, but not when the sync flag is modified by for instance some background code. |
But maybe let's do it after the other 4.5 things and could also be good to discuss (dis)advantages in a talk |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works perfectly
app/src/main/kotlin/at/bitfire/davdroid/repository/SyncOnCollectionsChangeListener.kt
Show resolved
Hide resolved
I still wonder why we really want to couple it on the data layer and not in the UI layer. Advantage of data layer: independent from UI – when collections are for instance changed by managed settings or other circumstances, sync would still run again Risk of data layer: we don't know when collections are really updated. For instance, we may at some time update the collection properties (calendar name, color, …) during the first PROPFIND of a sync, as we have thought about often. In that case a sync could automatically trigger another sync. I think the basic question is: what's our goal?
I'm not sure yet, but I think it would be more safe to trigger this on UI layer instead, at least for now. What are your thoughts? |
Besides having I think that's still clean architecture and it would solve the issue of unintentional syncs of other collection changes.
I think both ways can be equally safe. Going the UI route is probably a bit less complex. |
If it reacts on DB changes, why not also when the title (→ calendar name), color etc. changes (during a collection list refresh)? So Two things:
We could use With
|
This would increase the likelihood of enqueuing new unneccessary syncs though, no? Like you mentioned:
I do think however this would could be neglectible if we replace only enqueued workers. So not replace a running sync worker ( I think this way we could reduce the amount of unecessary syncs considerably. Unfortunately it seems like workmanager does not have this feature inbuilt. So if we'd want only the latest request to run after the currently running one, that means to have at most two "active" workers:
We would need to do some querying ourselves before appending new requests, like so: val activeCount = WorkManager.getInstance(context)
.getWorkInfosForUniqueWork("onetime-sync ...")
.get()
.count {
it.state == WorkInfo.State.RUNNING || it.state == WorkInfo.State.ENQUEUED
}
if (activeCount < 2)
WorkManager.getInstance(context).enqueueUniqueWork(
"onetime-sync ...",
ExistingWorkPolicy.APPEND,
workRequest
) Now for your two things:
I'd love to have a call on this issue too 🔄 |
Discussed in call. Too risky. Hard to oversee potential problems. Infinite detection-sync loops etc. We will create a new PR with UI triggers to test the water first. |
Purpose
Nice to have for:
Short description
SyncWorkerManager
listen to any collection changes and use the account passed along toChecklist