bitfireAT / davx5-ose

DAVx⁵ is an open-source CalDAV/CardDAV suite and sync app for Android. You can also access your online files (WebDAV) with it.
https://www.davx5.com
GNU General Public License v3.0
1.48k stars 74 forks source link

Provide database `Collection` to `SyncManager` #875

Closed rfc2822 closed 2 months ago

rfc2822 commented 3 months ago

Providing the respective database Collection to the SyncManager will allow us to reduce our dependency of the content providers.

For instance, we can then take the address book/calendar URL from the DB Collection.url field instead of caching it in the content provider and then taking it from there.

Right now, we have two main steps in the Syncer (let's take the CalendarSyncer as an example):

  1. (Do some other stuff, like handling colors.)
  2. updateLocalCalendars: sync the DB collections of type "calendar" with the Android content provider (the collections themselves, not the contents)
    • Create local calendars (= calendar in the content provider) for syncable collections that don't have a local calendar yet.
    • Update existing local calendars according to database and settings (title, URL, read/only flag, colors, …).
    • Delete existing local calendars that shall not be synced (anymore).
  3. Iterate through all local calendars and sync them with a CalendarSyncManager. In this step, we don't have the DB collection anymore, so we can't pass it to the SyncManager.

Now we want the DB collection to be available for the SyncManager. My approach would be to combine the main steps in the Syncer:

  1. (Do some other stuff, if necessary.)
  2. Sync list of DB collections with local calendars (the collections themselves, not the contents):
    • Create/update local calendar according to the database when needed like we already do.
    • Still in the same scope, we still have the DB collection and can pass it to the SyncManager. So we call the SyncManager here and pass the DB Collection.
    • Delete existing local calendars that shall not be synced (anymore).
sunkup commented 3 months ago

Maybe I misunderstand something here, but if we create the syncManager in step 2. we would either

I suggest we instead access the already existing remoteCalendars map in step 3. using the localCalendar "name" (url) to retrieve the db collection from the remoteCalendars map and stick with creating the syncManager here, passing in the db collection before syncing.

What I mean: https://github.com/bitfireAT/davx5-ose/pull/881/commits/0fcb992ad0cba878e14ed53b96afd03ca8db8f05

rfc2822 commented 3 months ago

have to perform the sync right away -> not good, because we have not yet created new local calendars

Yes, I thought we can create/update and & sync each calendar directly, without having to create/update/delete other calendars first.

However if it's cleanly possible to still do sync in step 3, even better, then the sync algorithm stays as it is and we have the collection available nevertheless.

sunkup commented 3 months ago

However if it's cleanly possible to still do sync in step 3, even better, then the sync algorithm stays as it is and we have the collection available nevertheless.

Good, then I will do that for the other Syncers (Jtx, AddressBook, etc) as well now :+1: