mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-02 18:18:39 +00:00
Improve user profile picture loading speeds (#248)
* Improve user profile picture loading speeds * Return null instead of an empty string For users that don't exist
This commit is contained in:
parent
0d6e40a75d
commit
6588176551
1 changed files with 16 additions and 2 deletions
|
@ -32,6 +32,20 @@ public class UserController : ControllerBase
|
||||||
return user?.Serialize(gameVersion);
|
return user?.Serialize(gameVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task<string?> getSerializedUserPicture(string username)
|
||||||
|
{
|
||||||
|
// use an anonymous type to only fetch certain columns
|
||||||
|
var partialUser = await this.database.Users.Where(u => u.Username == username)
|
||||||
|
.Select(u => new
|
||||||
|
{
|
||||||
|
u.Username,
|
||||||
|
u.IconHash,
|
||||||
|
}).FirstOrDefaultAsync();
|
||||||
|
if (partialUser == null) return null;
|
||||||
|
string user = LbpSerializer.TaggedStringElement("npHandle", partialUser.Username, "icon", partialUser.IconHash);
|
||||||
|
return LbpSerializer.TaggedStringElement("user", user, "type", "user");
|
||||||
|
}
|
||||||
|
|
||||||
[HttpGet("user/{username}")]
|
[HttpGet("user/{username}")]
|
||||||
public async Task<IActionResult> GetUser(string username)
|
public async Task<IActionResult> GetUser(string username)
|
||||||
{
|
{
|
||||||
|
@ -51,7 +65,7 @@ public class UserController : ControllerBase
|
||||||
if (token == null) return this.StatusCode(403, "");
|
if (token == null) return this.StatusCode(403, "");
|
||||||
|
|
||||||
List<string?> serializedUsers = new();
|
List<string?> serializedUsers = new();
|
||||||
foreach (string userId in u) serializedUsers.Add(await this.getSerializedUser(userId, token.GameVersion));
|
foreach (string userId in u) serializedUsers.Add(await this.getSerializedUserPicture(userId));
|
||||||
|
|
||||||
string serialized = serializedUsers.Aggregate(string.Empty, (current, user) => user == null ? current : current + user);
|
string serialized = serializedUsers.Aggregate(string.Empty, (current, user) => user == null ? current : current + user);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue