Skip to content
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

[Bug]: Duplicate users in search #553

Open
L-e-x-o-n opened this issue Jan 8, 2025 · 1 comment
Open

[Bug]: Duplicate users in search #553

L-e-x-o-n opened this issue Jan 8, 2025 · 1 comment
Labels
bug Something isn't working good first issue Good for newcomers low priority

Comments

@L-e-x-o-n
Copy link
Collaborator

L-e-x-o-n commented Jan 8, 2025

Describe the Bug

Admin user search can return duplicate users for specific conditions search terms (described in detail below).

From index/2 inTeiserverWeb.Admin.UserController

    users =
      Account.list_users(
        search: [
          basic_search: Map.get(params, "s", "") |> String.trim()
        ],
        order_by: "Newest first",
        limit: 50
      )

    # Sometimes we get a lot of matches so it can be good to put in place exact matches too
    exact_match =
      if Enum.count(users) > 20 && params["s"] do
        Account.list_users(search: [name_lower: params["s"]])
      else
        []
      end

    users = (exact_match ++ users) |> Enum.reject(&(&1 == nil))
    user_stats = for user <- users, do: Account.get_user_stat_data(user.id)

Basic search is returning a list of users whose name or email contains the search term. Exact search returns a list of users whose names are an exact match to the search term (case insensitive).

In the final user list, exact match search is added first so that people can find users faster if they have their exact name (and there are more than 20 results from basic search).

Reproduce the bug

To reproduce this bug the search term must be an exact (case insensitive) match to an user name while also contained in more than 20 other user names or emails.

Screenshots

image

Additional context

Exact search is helpful because it shows the user you are most likely searching for (by knowing their exact name) first, a fix should remove the duplicate user while keeping the exact matched user at the top.

@L-e-x-o-n L-e-x-o-n added bug Something isn't working good first issue Good for newcomers low priority labels Jan 8, 2025
@NortySpock
Copy link
Contributor

Would it make sense to push this down to a single SQL query, and ask the database to give you a sorted list? Naively, the way it's written, it appears the database would have to serve two requests, rather than one.

Sorry, SQL is my mother tongue, so that's what I reach for first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers low priority
Projects
None yet
Development

No branches or pull requests

2 participants