users fetch: Added an api to query multiple users in a single request#89
users fetch: Added an api to query multiple users in a single request#89AkhileshA wants to merge 3 commits intoVarunda:masterfrom
Conversation
|
how come this needs to be a user search? could getting users by just name work fine too? |
|
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 |
0c533aa to
b0e80f4
Compare
|
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 |
There was a problem hiding this comment.
this can be a GET, no reason for a POST here. just have users be a [FromQuery]
There was a problem hiding this comment.
users.Count > 50, 50 users would error
There was a problem hiding this comment.
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
| /// <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) { |
There was a problem hiding this comment.
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) { |
| } | ||
|
|
||
| List<ApiBarUser> apiUsers = await _UserRepository.GetByUsernames(usernames, includePreviousNames, cancel); | ||
| _Logger.LogInformation($"Found {apiUsers.Count} users matching usernames"); |
| } | ||
|
|
||
| using NpgsqlConnection conn = _DbHelper.Connection(Dbs.MAIN); | ||
| IEnumerable<BarUserSkill> skills = (await conn.QueryAsync<BarUserSkill>(new CommandDefinition( |
| 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() }, |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
why declare this as an IEnumerable then use .ToList() here?
Added an API
search/batchto theUserApiControllerderieved 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