mentrena / SyncKit

Automatic CloudKit synchronization
https://mentrena.github.io/SyncKit/
MIT License
505 stars 57 forks source link

Owners changes in shared database re-uploaded by the guest #164

Closed torfluor closed 2 years ago

torfluor commented 3 years ago

The owner have a set of objects that he have shared with another user (the guest). If the guest changes the object the sync runs as expected:

Log from the owners side:

Got notification about changes in remote PRIVATE database
"CloudKitSynchronizer >> Initiating synchronization"
"QSCloudKitSynchronizer >> Downloaded 1 changed records >> from zone <CKRecordZoneID: 0x118c773f0; ownerName=__defaultOwner__, zoneName=TimelinePresenterZone>"
"QSCloudKitSynchronizer >> Downloaded 0 deleted record IDs >> from zone <CKRecordZoneID: 0x118c773f0; ownerName=__defaultOwner__, zoneName=TimelinePresenterZone>"
"Finished applying pending relationships"
Finished syncing with private iCloud
"QSCloudKitSynchronizer >> Finishing synchronization"

But, if the owner changes the object, the guest re-uploads the object:

Log from the owner:

Syncing private realm
"CloudKitSynchronizer >> Initiating synchronization"
"QSCloudKitSynchronizer >> Uploaded 1 records"
Finished syncing with private iCloud
"QSCloudKitSynchronizer >> Finishing synchronization"
Got notification about changes in remote PRIVATE database
"CloudKitSynchronizer >> Initiating synchronization"
"QSCloudKitSynchronizer >> Downloaded 1 changed records >> from zone <CKRecordZoneID: 0x10ed1ced0; ownerName=__defaultOwner__, zoneName=TimelinePresenterZone>"
"QSCloudKitSynchronizer >> Downloaded 0 deleted record IDs >> from zone <CKRecordZoneID: 0x10ed1ced0; ownerName=__defaultOwner__, zoneName=TimelinePresenterZone>"
"Finished applying pending relationships"
Finished syncing with private iCloud
"QSCloudKitSynchronizer >> Finishing synchronization"

Log from the guest:

Got notification about changes in remote SHARED database
"CloudKitSynchronizer >> Initiating synchronization"
"QSCloudKitSynchronizer >> Downloaded 1 changed records >> from zone <CKRecordZoneID: 0x12760d930; ownerName=_e8647c75895bce5ddf0bf63d165c25b5, zoneName=TimelinePresenterZone>"
"QSCloudKitSynchronizer >> Downloaded 0 deleted record IDs >> from zone <CKRecordZoneID: 0x12760d930; ownerName=_e8647c75895bce5ddf0bf63d165c25b5, zoneName=TimelinePresenterZone>"
 notification: name = QSModelAdapterHasChangesNotification, object = Optional(<SyncKit_RealmSwift.RealmSwiftAdapter: 0x12a11e6c0>), userInfo = nil
"Finished applying pending relationships"
Syncing private realm
"CloudKitSynchronizer >> Initiating synchronization"
"QSCloudKitSynchronizer >> Uploaded 1 records"
Finished syncing with private iCloud
"QSCloudKitSynchronizer >> Finishing synchronization"
Finished syncing with shared iCloud
"QSCloudKitSynchronizer >> Finishing synchronization"
"CloudKitSynchronizer >> Initiating synchronization"
Finished syncing with shared iCloud
"QSCloudKitSynchronizer >> Finishing synchronization"
mentrena commented 2 years ago

Hi @torfluor , I haven't been able to reproduce this using the example project, is it possible that your app is actually changing the object on the guest side after it's downloaded, causing the extra upload?

Mr-ZNN commented 2 years ago

The guest must have modified the PrimaryKey of the record, which caused the record to change and generate a new record.

mentrena commented 2 years ago

Closing here, issue had to do with having two different synchronisers for the same realm, so one was picking up changes made by the other.