Search code examples
javascriptgoogle-drive-apigoogle-drive-realtime-api

Concurrent grouping operation in a hierarchical structure


Given a tree of objects in Drive Realtime API with a concurrent operation in two or more clients where existing children are moved into a new parent (think of a grouping operation in a graphical editor), what is the best datastructure to avoid a) duplicate existing children and b) empty new parents?


Solution

  • Can each child only have a single parent?

    If that is the case, I would suggest having a "parent" field on the child objects. This guarantees that each child only has one parent, and the non-empty parent set is implicitly created by looking finding all the parents.

    You could easily maintain this parent set by doing a one-time scan through the children on startup, and then listening for change events on the child and updating the set accordingly.1111