• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
2-Way-Sync last modified - But keep old annotations
#1
Lightbulb 
I am working on a project, where a server automatically generates .pdf files of all parts whenever a musescore .mscz is updated.
I would like to sync these into my cloud backup/sync (e.g. Dropbox) to update my devices with the latest .pdf files.
On the other hand, since most parts dont change, all the time (e.g. the Trombone is untouched, only Sax was changed), I want to keep annotations made on my device on an older file.

My actual javascript goes like this:
  1. find newly generated .pdf files e.g. (Gallowstreet - A Trip Worth Making - Trombone.v5.pdf)
  2. open mobilesheets.db and list all Files in library
  3. Find files with similar naming but different version (e.g.  Gallowstreet - A Trip Worth Making - Trombone.v4.pdf)
  4. compare version strings and abort if library version is equal or newer
  5. copy new .pdf (e.g. v5) to Dropbox and remove old (v4)
  6. update db File.Path, LastModified, FileSize and Hash (in Future, maybe also pages etc.)
  7. find and update entry in mobilesheets_hashcodes.txt

One thing i had to learn is, that 2-Way-Sync does not look for LastModified date of the file, but for LastModified of the song.
So, whenever I update a File, I make sure to 
8. also update the LastModified of the corresponding Song.

This allows me to update the pdf files of all my songs, but I lose annotations of files, that are updated. Files that are not updated keep their annotations, even though i mark the Song as updated.

Can we have the option to keep old annotations, if File is updated but File.Id is kept?
Reply
#2
Modifying a file absolutely should not remove annotations unless you are embedding the annotations in the PDF itself. If you do that, then replacing the file of course removes all the annotations, as they were in the file you replaced. The annotations are stored in the database.

Mike
Reply
#3
You are right, annotations are generally not lost, but they are also not merged with in 2-Way-Sync:

Device:
 - Song 1 (last changed 2h ago)
    - File A (last changed 10d ago)
      - Annotation X (added 5min ago)
    - File B.v3 (last changed 1s ago)

Cloud:
 - Song 1 (last changed 1s ago)
    - File A.v2 (last changed 1s ago)
    - File B.v2 (last changed 20s ago)

If i sync in either direction, obviously the state is copied correctly. 
Device -> Cloud: I now have Song 1, File A with Annotation X and File B.v3 in the Cloud (as well as on the Device), so yes Annotation is kept
Cloud -> Device: I now have Song1, File A.v2 and File B.v2 on the Device (as well as in the Cloud), Annotation is lost

2-Way-Sync now only looks at change date of the Song and keeps the one in the Cloud, because it was changed more recently. However it keeps that Song together with all its files and their annotations. Result is the same as Cloud -> Device, Annotation is lost

What I want is a deep 2-Way-Sync, where the Date of the Song might actually be ignored. Instead File and Annotation lastModified time are checked. 

e.g. if File A and File A.v2 have the same Id, the one with the more recent change is kept, in this case its A.v2 (Cloud -> Device)
For File B its the other way arround, because the file on the Device is newer than the one in the Cloud (Device -> Cloud)
The Annotation does not exist in the Cloud, so it should be copied there as an Annotation for File A.v2.

Final outcome would look like this:

Device & Cloud:
 - Song 1
    - File A.v2 (last changed 1s ago)
      - Annotation X (added 5min ago)
    - File B.v3 (last changed 1s ago)
Reply
#4
Annotations cannot be merged on an individual basis, because there is no way to uniquely identify them and correctly match them up between devices with 100% accuracy. There is no requirement that each device has an identical library, which means I can't assume the database IDs match up or anything of that sort. If an annotation is modified, the app could try to guess if the modified annotation on one device matches one of the existing annotations on the other device, but if the app gets this wrong, I doubt users would be okay with their annotations being completely messed up by an incorrect merge.

As far as files go, I reviewed the logic, and the code is not correctly looking for a newer version of a file when a two-way sync is used. I'll update this so it uses the last modified timestamp to determine which file to use.

Annotations are completely independent from files in terms of how they are stored.  You can swap in a new version of a PDF and the annotations aren't impacted, which is why it's designed this way. So it's perfectly plausible that a sync could take a newer version of a file from one device, but annotations from the other device, depending on the song's last modified timestamp compared with the file's last modified timestamp. 

Mike
Reply
#5
You are right. I completely forgot that the Ids are not unique like UUIDs and also not synced to a global mobilesheets server.

Thank you for looking into this. I will try again, when the File date is supported.

Ah, I understand now. Annotation(Base) are linked to Songs with a specific page x. So they will be displayed independet from whatever file is displayed on page x for the Song.

Thanks for your help!
Reply
#6
That is correct. That's what allows the file to be swapped out.

Mike
Reply




Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2025 MyBB Group.