0

I want to delete the yellow user in the screenshot if he decides to delete his account. The blue X is a different user. How do I do that?

In the second picture is my attempt. I don't know how to get the userid of the blue X.

1

2

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Please don't post screenshots of your code, or other textual content. Instead post the actual text, and use the formatting tools of Stack Overflow to mark it up. – Frank van Puffelen Nov 18 '21 at 15:28
  • Please provide enough code so others can better understand or reproduce the problem. – Community Nov 21 '21 at 08:25

1 Answers1

0

Your current data structure makes it easy to find the yellow Followers for a given blue Follow node. It does not however make it easy to find the blue node for a given yellow one. In fact, to allow that you will have to read all blue nodes, and check each individual Followers child node in turn.

To more easily allow your use-case, you'll want to also store the inverse data structure that allows you to find the blue Follow nodes for a given yellow Follower value. I typically refer to this as the Followee map, although I admit I'm not sure if that's even a word:

Followees: {
  "ky....Yhi1": {
    "L5w...6rF3": true
  }
}

Now with this structure, you can find the "L5w...6rF3" key based on knowing the "ky....Yhi1" value and delete the user from the Followers node there.

We covered this scenario a few times before, so I recommend also checking out:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807