[Android] Not syncing in background, causing conflicts?

Operating system

Android

Joplin version

3.6.18

Sync target

Nextcloud

What issue do you have?

A couple, possibly interrelated issues:

  1. The Joplin app does not appear to be syncing in the background, only while the app is open in the foreground. This is most apparent when I had initiated a history clearing operation for one frequently updated note (over 100 operations required). If I switched away from the app then came back, the progress would not have changed.
  2. Conflicts often created for the aforementioned frequently updated note. I have to wonder if this is because of the previous problem, so when I update the note again before the first changes have a chance to sync, Joplin sees this as a conflict.

There are no changes being made on the remote for this specific note so Joplin shouldn't be recording a conflict on both ends.

Log file

mobile-log.log (2.21 MB)

Further research

Yes the conflicts are most certainly caused by the lack of background sync on the mobile app. If there is a large sync operation, you should set aside some time to let it complete, otherwise it can block incoming changes to the note being synced until all the other changes have completed first. When sync is fully completed on all devices, syncing should usually be small and incremental.

Thanks for replying @mrjo118 ,

When sync is fully completed on all devices, syncing should usually be small and incremental.

This is usually where the conflicts are occurring: I make a small change to a single note on my phone, and then depending on how quickly I switch out of the app, the conflicts start happening. For some reason Joplin thinks that changes have happened on the server side too which is almost never the case, it may just be that Joplin has "forgotten" the previous note's state, so when it compares to the server, it thinks a change has happened. My Nextcloud server also has to work fairly hard when Joplin syncs a change, and average sync time for a single change seems to be about 5-10 seconds.

One thing I'm wondering is, can I have Joplin sync to Nextcloud's directory structure on my phone, and let the Nextcloud app (which does do background sync) handle the sync part?

When sync is fully completed on all devices, syncing should usually be small and incremental.

I'm not saying that will prevent conflicts completely, I'm saying that it should keep the sync reasonably quick. But yes if you want to avoid conflicts you'll have to wait those 5-10 seconds before switching app or turning the screen off. Or alternatively, don't wait after every time you change a note, but remember to do a manual sync on your phone beforehand, every time you wish to make changes on a different device.

You can, but it's not worth considering because the sync will be super slow that way due to performance limitations of Android SAF, when there are many files in a single directory

Good advice to not sync every time; I've turned off auto sync now and will just try to remember to manually sync from time to time. I might try to fiddle around with Nextcloud's new two-way directory sync and see if that can mitigate any potential issues with the Android SAF, although I suspect you're right regardless and I'll be back to square one. Thanks for dropping in here to help and offer input and knowledge!

You can't mitigate the performance issues with Android SAF unless you always have a small number of sync objects (after around 1000 sync objects, it starts to slow down exponentially).

It's a long time complaint from Android developers that SAF performance is so poor, and the only way to get around it is to not use SAF at all. But that would require either rooting your phone to allow Nextcloud to access the Joplin app directory, or modifying the Joplin app to use the standard file api, which would then require an access to all files permission. That is not done in Joplin, because there is a very strict criteria for an app to be allowed to be published to the play store, if it has that permission.