Skip to content

schema to delete a user. #4685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
joaoarmando opened this issue Mar 30, 2018 · 4 comments
Closed

schema to delete a user. #4685

joaoarmando opened this issue Mar 30, 2018 · 4 comments

Comments

@joaoarmando
Copy link

I'm facing some difficulties with updating counters.
I'm developing a "social networking" application, this is my first application.
In the scenario, we have the following situation:
User X has 300 followers.
User Y will in turn follow user X, then I will go to the Follows counter of user X and increase by 1, user X happens to have 301 followers now, and I also go to user Y who has followed up, and increased your following counter at 1.
The problem lies in, if user X, resolves to delete your account, I will have to make 301 calls, for each of the followers of user X, and decrease the following counter of all those users at -1, That is the way correct to do this?
-Sorry my english, i'm using translator

@paulovitin
Copy link
Contributor

Based on your scenario, yes, you need to do this, but this operation dont need to happen in the same time of user delete his account. You can do this in background gradually.

The answear is based in your scenario. :)

@JacobJT
Copy link

JacobJT commented Apr 5, 2018

Instead of storing the number, you could calculate it if you had a Follower join table. Then you could just do a query.count() with constraints for the current user following / being followed to get the counts. You'd also be able to use that as a matchesQuery constraint to get feeds and what not.

@joaoarmando
Copy link
Author

@JacobJT I have in the user class, a relation with all the users that follow it, I must make a query.count (); in relation if so. The parse will not have to count all objects 1 by 1?

@JacobJT
Copy link

JacobJT commented Apr 5, 2018

@joaoarmandoo I haven't worked a ton with relations so I'm not sure how their counts work. Join tables are a fairly common solution for this, though. A Following class, with Follower user pointer and Following user pointer, and you could do var query = new Parse.Query("Following").equalTo("Following", currentUser) would let you do a count. It does take a server call each time, but it shouldn't be too hard on the server / db as long as you have indexing on the Follower and Following fields. It would be a simpler solution than having to update the relation on every single object.

That being said, you could also update the beforeDelete handler for users to call another function that takes the user's followers / following relations and removes them from each user. You wouldn't be able to have it be a success condition, though, as it would take too long and the destroy would time out.

The Join Table is how I would implement this, if you were starting from scratch or are still in a dev phase where you could swap out the implementation, but without knowing how extensively that relation is built into your code base or the full potential of relations, I can't say with certainty that it's the best solution for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants