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

Don't try to sync deleted collections #1064

Conversation

sunkup
Copy link
Member

@sunkup sunkup commented Oct 9, 2024

Purpose

Syncer tries to sync collections it deleted causing an exception. The sync algorithm is the heart of DAVx5 and so it should run flawlessly, be easy to understand and well documented.

Short description

It would have been possible to simply get the collections anew from the database, after updateCollections has run and possibly deleted some local collections. It would, however, not have been as explicit in the sense that we would have relied on a side effect of updateCollections.

By returning a pair (which is ugly yes) it is more explicit. We also save a database query and made the deletion test stronger.

Actual changes:

  • Return list of deleted local collections from updateCollections
  • Remove the deleted local collections from the list of collections to be synced
  • Update KDoc
  • Update tests

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 added the bug Something isn't working label Oct 9, 2024
@sunkup sunkup requested a review from ArnyminerZ October 9, 2024 13:03
@sunkup sunkup self-assigned this Oct 9, 2024
@sunkup sunkup linked an issue Oct 9, 2024 that may be closed by this pull request
@rfc2822
Copy link
Member

rfc2822 commented Oct 9, 2024

Maybe deprecated by #1065?

Copy link
Member

@ArnyminerZ ArnyminerZ left a comment

Choose a reason for hiding this comment

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

Just a small thing

@@ -96,15 +96,20 @@ abstract class Syncer<CollectionType: LocalCollection<*>>(

// Find collections in database and provider which should be synced (are sync-enabled)
val dbCollections = getSyncEnabledCollections()
val localCollections = getLocalCollections(provider).toMutableList()
var localCollections = getLocalCollections(provider).toMutableList()
Copy link
Member

Choose a reason for hiding this comment

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

Does it need to be var?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, not at all. 👍


// Create new local collections for newly found remote collections
val newProviderCollections = createLocalCollections(provider, newDbCollections)
localCollections.addAll(newProviderCollections) // Add the newly created collections

// Don't sync deleted collections
deletedLocalCollections.forEach { deletedLocalCollection ->
localCollections.remove(deletedLocalCollection)
Copy link
Member Author

@sunkup sunkup Oct 10, 2024

Choose a reason for hiding this comment

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

In order to have the actual deletion and the deletion from to-be-synced-list at the same place, deleting from the list too could happen inside of updateCollections too and we return the finished list.

for (localCollection in localCollections) {
val dbCollection = dbCollections[localCollection.collectionUrl?.toHttpUrlOrNull()]
if (dbCollection == null)
if (dbCollection == null) {
// Collection not available in db = on server (anymore), delete obsolete local collection
localCollection.deleteCollection()
Copy link
Member Author

Choose a reason for hiding this comment

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

In order to have the actual deletion and the deletion from to-be-synced-list at the same place, this could happen outside of updateCollections where we delete from the list too.

@rfc2822
Copy link
Member

rfc2822 commented Oct 10, 2024

Obsoleted by #1065

@rfc2822 rfc2822 closed this Oct 10, 2024
@rfc2822 rfc2822 deleted the 1062-syncer-tries-to-sync-collections-that-it-just-has-deleted branch October 10, 2024 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Syncer tries to sync collections that it just has deleted
3 participants