Skip to content

searchUsers method is very slow to return data when searching for common words #16

Closed

Description

@TheHanna

for (int i = 0; i < 100; i++) { // Start at page 0 and increment each time until there are no more valid pages
JsonObject jsonObject = httpUtils.urlRequestPOST(HttpUtils.URL_BASE + "/User/Search/GlobalName/" + i + "/", body);
// Only continue looping if the result has a list of search results
if (jsonObject.has("Response") && jsonObject.getAsJsonObject("Response").getAsJsonArray("searchResults").size() != 0) {
JsonArray jsonArray = jsonObject.getAsJsonObject("Response").getAsJsonArray("searchResults");
for (JsonElement jsonElement : jsonArray) { // Add all user info objects into one list
jsonObjects.add(jsonElement.getAsJsonObject());
}
} else {
break;
}
}

Paginating through the API automatically to get all the data at once is an inefficient way handle search. This is slow when searching for common terms in a username, i.e. "guardian"

Ideally, you should simply expose the pagination and allow developers to customize this a bit so that it can be performant

Activity

  1. dec4234 commented on Mar 10, 2022

    @dec4234
    Owner

    Do you have something like an Iterator in mind using hasNext() and next()?

  2. added a commit that references this issue on May 6, 2024
  3. dec4234 commented on May 6, 2024

    @dec4234
    Owner

    This has now been settled with the addition of Pagination and the updated #searchUsers(String name).
    Thank you for your suggestion. Please let me know if there are any further issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions