Skip to content

users fetch: Added an api to query multiple users in a single request#89

Open
AkhileshA wants to merge 3 commits intoVarunda:masterfrom
AkhileshA:feature/fetchmultipleusers
Open

users fetch: Added an api to query multiple users in a single request#89
AkhileshA wants to merge 3 commits intoVarunda:masterfrom
AkhileshA:feature/fetchmultipleusers

Conversation

@AkhileshA
Copy link

@AkhileshA AkhileshA commented Nov 1, 2025

Added an API search/batch to the UserApiController derieved mostly from the search api to request player data for multiple users in a request. Limited the number of users that can be requested by 50

@Varunda
Copy link
Owner

Varunda commented Nov 1, 2025

how come this needs to be a user search? could getting users by just name work fine too?

@Varunda
Copy link
Owner

Varunda commented Nov 1, 2025

talked about this more in Discord, gonna move to just a getting user by name instead of user ID, which removes the need for searching

@AkhileshA AkhileshA force-pushed the feature/fetchmultipleusers branch from 0c533aa to b0e80f4 Compare November 2, 2025 16:59
@AkhileshA
Copy link
Author

made the needed changes. Used the same models from the fetch user GET api as this is just trying to get multiple users at once

@AkhileshA AkhileshA changed the title user_search: Added an api to query multiple users in a single request users fetch: Added an api to query multiple users in a single request Nov 2, 2025
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be a GET, no reason for a POST here. just have users be a [FromQuery]

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

users.Count > 50, 50 users would error

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to check if users is null, i have strict nullity turned on for this project. just a check for users.Count == 0 is fine

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this, unneeded

/// <returns>
/// a dictionary mapping user IDs to lists of <see cref="BarUserSkill"/>s
/// </returns>
public async Task<Dictionary<long, List<BarUserSkill>>> GetByUserIDs(List<long> userIDs, CancellationToken cancel) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strictly speaking we don't need a dictionary to return this, as BarUserSkill already has a UserID field

return ApiBadRequest<List<ApiBarUser>>($"usernames list cannot be empty");
}

if (usernames.Count >= 50) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is supposed to be a >

}

List<ApiBarUser> apiUsers = await _UserRepository.GetByUsernames(usernames, includePreviousNames, cancel);
_Logger.LogInformation($"Found {apiUsers.Count} users matching usernames");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unneeded, please remove

}

using NpgsqlConnection conn = _DbHelper.Connection(Dbs.MAIN);
IEnumerable<BarUserSkill> skills = (await conn.QueryAsync<BarUserSkill>(new CommandDefinition(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use conn.QueryListAsync here

using NpgsqlConnection conn = _DbHelper.Connection(Dbs.MAIN);
IEnumerable<BarUserSkill> skills = (await conn.QueryAsync<BarUserSkill>(new CommandDefinition(
"SELECT * FROM bar_user_skill WHERE user_id = ANY(@UserIDs)",
new { UserIDs = userIDs.ToArray() },
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to convert this to an array i think

"SELECT * FROM bar_user_skill WHERE user_id = ANY(@UserIDs)",
new { UserIDs = userIDs.ToArray() },
cancellationToken: cancel
))).ToList();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why declare this as an IEnumerable then use .ToList() here?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments