list - Users-Posts-Comments relationship implementation on reliable collections -


let's imagine have 3 classes: user,post, comment. standard actions — user can create posts , write comments these posts. have situation depicted below: enter image description here

i need perform these 3 queries quickly:

  • get comments post
  • get comments user
  • get post comment

and looks isn't possible if use partitioning. @ least not single reliable dictionary. need several dictionaries different queries. correct?

i'm working on same thing! first of all: schema bit different. have user, topic , comment. topic class list of comment ids(ienumerable long), nothing more. first comment post.

oh, first of all, little warning: i'm beginning service fabric, might doing wrong ;)

the user not relevant me. store userid on comment. when retrieving list of comments users stateful users service. or store users name in comment directly, not sure yet.

so leaves me topics , comments. first thought 'lets create stateful topicservice , stateful commentservice'. realised every topic load need call commentservice each comment comments.

so created topicservice handles 2 ireliabledictionaries: topics , comments.

whenever comment posted use topicid partitionkey , in partition comment stored. not using commentid !! way comments specific topic in same partition.

when loading topic comments use topicid partitionkey again, topic reliabledictionary topics , loop list of comment ids in reliabledictionary comments. not sure if helps, getcomments looks this:

        var topics = await this.statemanager.getoraddasync<ireliabledictionary<long, topicmodel>>("topics");         var comments = await this.statemanager.getoraddasync<ireliabledictionary<long, commentmodel>>("comments");          list<commentmodel> result = new list<commentmodel>();          using (var tx = this.statemanager.createtransaction())         {             conditionalvalue<topicmodel> topic = await topics.trygetvalueasync(tx, topicid);              if(topic.hasvalue)             {                 foreach(long commentid in topic.value.commentsinternal)                 {                     conditionalvalue<commentmodel> comment = await comments.trygetvalueasync(tx, commentid);                      if (comment.hasvalue)                         result.add(comment.value);                 }             }              await tx.commitasync();         }          return result; 

i'm not done yet, method more work.

perhaps helps :)

edit: ow, there disadvantage! when want load single comment id, need provide topicid. commentmodel class has commentid , topicid property.


Comments