Skip to content
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

Open
wants to merge 4 commits into
base: main-ose
Choose a base branch
from

Conversation

sunkup
Copy link
Member

@sunkup sunkup commented Jan 14, 2025

Purpose

Nice to have for:

Short description

  • Pass account of the changed collection along when notifying listeners of collections change.
  • Then have SyncWorkerManager listen to any collection changes and use the account passed along to trigger a one time sync of the whole account (not just the service which the collection belongs to - although that would prob be possible as well).

Checklist

  • The PR has a proper title, description and label.
  • I have self-reviewed the PR.
  • I have added documentation to complex functions and functions that can be used by other modules.
  • I have added reasonable tests or consciously decided to not add tests.

@sunkup sunkup requested a review from ArnyminerZ January 14, 2025 15:23
@sunkup sunkup marked this pull request as ready for review January 14, 2025 15:23
Copy link
Member

@rfc2822 rfc2822 left a 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.

Comment on lines +294 to +316
/**
* Listener that enqueues a push registration worker when the collection list changes.
*/
class CollectionsListener @Inject constructor(
private val workerManager: SyncWorkerManager
): DavCollectionRepository.OnChangeListener {

override fun onCollectionsChanged(account: Account?) {
account?.let { workerManager.enqueueOneTimeAllAuthorities(it) }
}

}

/**
* Hilt module that registers [CollectionsListener] in [DavCollectionRepository].
*/
@Module
@InstallIn(SingletonComponent::class)
interface SyncWorkerManagerModule {
@Binds
@IntoSet
fun listener(impl: CollectionsListener): DavCollectionRepository.OnChangeListener
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be in a separate file, because SyncWorkerManager's task is only to manage (enqueue, cancel) syncs.

The functionality that a method of SyncWorkerManager shall be called when collections change is a separate function and should be in a separate file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Automatically sync when collections are (un)checked "Force read-only" setting not effective immediately
2 participants