mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-11 20:00:30 +01:00
Feature: Importable synchronizable objects #67
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @ruslanskorb on GitHub (Jun 29, 2016).
Hi @JohnEstropia!
To synchronize the data created when the application was offline, we need to use an additional unique ID generated by the client. This ID can be included in the import source to update locally created objects.
Since I needed it I added a new protocol
ImportableSynchronizableObjectand related methods to theBaseDataTransactionclass.If you think that it might be useful for you or other users of CoreStore just let me know and I will create a pull request.
@JohnEstropia commented on GitHub (Jun 30, 2016):
Hmm... I may have misunderstood the requirement, but in this case shouldn't the local ID be the unique ID?
Also I'm not sure if allowing two independent unique IDs to exist is good (or at least flexible) design.
serverObjectIDValueis optional, how do we guarantee that we will never hit a case where two objects with differentlocalObjectIDValues have the sameserverObjectIDValue? (the synchronization becomes tightly-coupled to the client-server implementation)importSynchronizableObjects(...)seems to prioritize local objects. What if other apps need it the other way around?On the other hand, I appreciate the very clean code (and full documentation!). It's just that I think the current design/implementation is a bit app-specific.
Of course you are free to keep your fork and share your extension as you wish :)
@JohnEstropia commented on GitHub (Jul 1, 2016):
Thanks again for the feature suggestion! I'll close this for now, but feel free to keep sharing ideas! :)
@ruslanskorb commented on GitHub (Jul 1, 2016):
Thanks for the feedback!
You're right about the priority of local objects in
importSynchronizableObjects(...). I updated it and force pushed to my repo. Now all the objects are arranged according to their position in the source array.To answer the rest of your questions I need to describe the synchronization process.
The local object ID is the unique ID that is generated and used by the client to find and update the object in the local store.
The server object ID is also the unique ID that is generated by the server and used by the client to communicate with the server.
After creating a new object by the user (e.g., adding an entry in the notebook) the client generates and assigns a new local object ID to it.
Then:
importSynchronizableObject(…); in this case the local object ID will be used to find the local object and update its server object IDWhen the user receives a brand new object from the server (without the local object ID, because only the client stored it) the client imports it using the method
importSynchronizableObject(…). In this case the server object ID will be used to find and update the local object. If such an object does not exist the client will create a new one and generate and assign a new local object ID to it.Eventually we have only two cases when we assign the server object ID to the local object and not one of them does not allow to assign one and the same
serverObjectIDValueto local objects with differentlocalObjectIDValue.I don't describe here all the possible cases but this description should be enough to understand the role of
ImportableSynchronizableObjectin the synchronization process and to answer your questions.In any case, with time, I plan to describe the whole process of synchronization and share it with the developer community.
Thank you for reading this! :-]
@JohnEstropia commented on GitHub (Jul 2, 2016):
Thanks, I understand your synchronization process now. But I still think this design is a bit too app-specific for CoreStore's purposes.
Since you mention that the local ID is not stored in the server, you may want to check for a case where you might get duplicated objects.
You may be already aware of this, or I might just have misunderstood something else. If so, just disregard this comment :)
@ruslanskorb commented on GitHub (Jul 2, 2016):
Between step 1 and step 2 the client sends the local object ID to the server and receives and saves the server object ID. The server does not create the object at this moment, it is only generates and returns the server object ID that will be sent by the client to the server in step 2. In step 3 the server stores the object and assigns the server object ID (from step 1.5) to it.
So, on the next app execution, the client receives the previous object from the server and updates it using the server object ID.
In the case where the client re-sends "unsent" local object to the server the server object ID will be used to find and merge the server object. If such an object does not exist the server will create a new one and assign this server object ID to it.
So, we will never get duplicated objects :-]
@JohnEstropia commented on GitHub (Jul 2, 2016):
I see, so the server just pre-assigns the server ID but does not store it yet. That makes more sense now, thanks :) Sounds like a reliable method 👍
Between use cases like these and the need for compound unique keys, I might consider providing a more flexible way to import objects in the future. Thanks again for sharing your ideas!
@ruslanskorb commented on GitHub (Jul 2, 2016):
Glad to hear it! 👍
I also will think about other more flexible ways to import objects and share my ideas with you.
Thanks for all your comments!