Limit the maximum number of followed users
The followed users feature had performance issues which were fixed in https://gitlab.com/gitlab-org/gitlab/-/merge_requests/84856. To protect the feature from abuse and maintain good performance, setting ~"Application Limits" is necessary. Based on the [research](https://gitlab.com/gitlab-org/gitlab/-/issues/346435#note_924985502) 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. 1. User already follows 299 users. 2. 2 HTTP requests arrive to follow users x and y. 3. In an unfortunate scenario, both users would be followed. 4. 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.
issue