Google Drive Realtime API: doing atomic updates in a hierarchical data model while maintaining sort order -


i'm planning build todo app using google drive realtime api. have hierarchical structure, tasks can have sub-tasks, can have sub-tasks, etc. task can moved around freely, means it's position/index between it's siblings can change, it's possible move parent.

now know have take care on making these moves atomic when using realtime api. in video google engineers explain best way have flat representation of hierarchical model: each item/tasks has property points it's parent. way moving task parent takes 1 operation: changing parent property (instead of removing child list of 1 parent , adding child list of new parent: 2 operation > not atomic).

this can work fine project, except need maintain order of child tasks within parent tasks. how can when task knows it's parent? many thanks, ruben

i think should work: have each task point parent task, recommended. in addition, have each task keep sorted list of child tasks. then, when display list of child tasks user, filter out ones don't point correct parent. you'll have same task under multiple parents, user never see it.

the danger that, due race condition, end having task not listed in other task's list of children, think can't happen.

another way have each task store "sort order" value, real number. ui sorts them before displaying. if 2 users add tasks @ same location, there risk of them getting same value, shouldn't matter since order of 2 tasks isn't defined in case.


Comments