that mean if you press @ in the issue text editor, first 10 users are being selected and then query filter is applied, so if you user is 11th on a list - there sill be an empty list
I suggest to not limit scope there, but after matching users to a query
WatchersController#users_for_mention is building a SQL query scope. As such, the limit to 10 results is only applied after filtering the list with the supplied query (which in the case of the mentions autocomplete is the text entered after the @ character).
As such, we return either up to 100 users from the project if no further text was entered yet, or we return up to 10 users matching the query. If the desired user is not yet part of the result, the user has to enter a more specific search term. If this does not work as intended for you, please provide a concrete reproducible example demonstrating your specific issue.
In any case, returning an unbound result here is inadvisable since this could result in arbitrarily large responses which would have to be dealt with in the frontend. Otherwise, it could could result in slowdowns or even crashes there.
Here is a concrete, reproducible scenario on 7.0.3 (code is unchanged in current trunk). As noted by Holger, limit(10) is applied after the like filter in SQL, so the description above is not the actual cause. The actual cause is that the limit is applied before the visibility filter, which runs in Ruby:
scope=Principal.assignable_watchers.limit(10)# 10 users from the whole instanceusers=scope.sorted.like(params[:q]).to_ausers.reject!{|user|user.is_a?(User)&&!object.visible?(user)}# filtered afterwards
As soon as at least one character is typed after @, the candidates are the first 10 matching users of the whole instance (sorted by name), and only then are the users who cannot see the issue removed. On an instance with many users spread across private projects, those 10 users usually belong to other projects, so the list ends up empty even though matching project members exist.
Steps to reproduce
Create a private project P with member "Zoe Martin" (role with "View issues").
Create 10 other active users whose name or login matches "m" (e.g. "Marc A01" ... "Marc A10") who are not members of P (or members of another private project).
As a user allowed to add watchers in P (role with users visibility "All active users"), open an issue of P and type @m in the notes.
Expected: Zoe Martin is suggested. Actual: the list is empty: the 10 "Marc" users are selected by the SQL query, then all removed because they cannot see the issue.
On our instance (~1,400 active users, mostly in private projects of ~70 members each), typing any one- or two-letter prefix (@a, @fr, @ma, @c...) returns 0 suggestions on most issues, while 3 to 20 project members match. Only typing almost the full login works.
Suggested fix
Search project members first, then fill with other users, and apply the visibility filter before the limit:
The candidates are still restricted by Principal.visible and by object.visible?(user), so no additional user is exposed: these are the same users that were reachable before by typing a longer query. We applied this patch on our production instance: suggestions now appear for short prefixes, with response times under 250 ms.