Limit the maximum number of followed users
The followed users feature had performance issues which were fixed in !84856 (merged). To protect the feature from abuse and maintain good performance, setting Application Limits is necessary.
Based on the research on GitLab.com, let's introduce a limit on the number of users a given user can follow.
How
Add an extra validation to the Users::UserFollowUser
model that checks the already followed user count and marks the model invalid when the threshold (300) is reached.
Minor concern 1
Such count validation is not 100% reliable: when several requests (follow user x) arrive at the same time the count might be skewed. This is a minor concern, we can safely ignore.
- User already follows 299 users.
- 2 HTTP requests arrive to follow users x and y.
- In an unfortunate scenario, both users would be followed.
- Following another user will result in a validation error.
Minor concern 2
On self-managed, there might be users who are over the limit (300). This is a very unlikely scenario however, we should probably add a note somewhere:
If you follow more than 300 users, you can unfollow users without any limit however, while you're over the limit, following new users is not allowed.