mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-05-16 06:32:28 +00:00
StasticsHelper + Community Tab Performance Fix (#713)
* Player count shows per game * Fixed LBP3 categories lagigng & StatisticsHelper Co-authored-by: koko <sudokoko@users.noreply.github.com> * Fixed "planetStats" mmPicksCount * Hopefully the final update to this PR! (Bug fixes) * Update ProjectLighthouse/Types/Entities/Level/Slot.cs Co-authored-by: koko <68549366+sudokoko@users.noreply.github.com> * Update ProjectLighthouse.Servers.GameServer/Controllers/Slots/SlotsController.cs I'm trusting you that nothing breaks here lol Co-authored-by: Josh <josh@slendy.pw> * Update ProjectLighthouse.Servers.GameServer/Controllers/Slots/SlotsController.cs bad slendy >:( Co-authored-by: koko <68549366+sudokoko@users.noreply.github.com> --------- Co-authored-by: koko <sudokoko@users.noreply.github.com> Co-authored-by: koko <68549366+sudokoko@users.noreply.github.com> Co-authored-by: Josh <josh@slendy.pw>
This commit is contained in:
parent
14e40de18f
commit
9b014fa01c
12 changed files with 19 additions and 13 deletions
|
@ -280,7 +280,7 @@ public class SlotsController : ControllerBase
|
||||||
.Take(Math.Min(pageSize, 30));
|
.Take(Math.Min(pageSize, 30));
|
||||||
string response = Enumerable.Aggregate(slots, string.Empty, (current, slot) => current + slot.Serialize(gameVersion));
|
string response = Enumerable.Aggregate(slots, string.Empty, (current, slot) => current + slot.Serialize(gameVersion));
|
||||||
int start = pageStart + Math.Min(pageSize, ServerConfiguration.Instance.UserGeneratedContentLimits.EntitledSlots);
|
int start = pageStart + Math.Min(pageSize, ServerConfiguration.Instance.UserGeneratedContentLimits.EntitledSlots);
|
||||||
int total = await StatisticsHelper.TeamPickCount(this.database);
|
int total = await StatisticsHelper.TeamPickCountForGame(this.database, token.GameVersion);
|
||||||
|
|
||||||
return this.Ok(generateSlotsResponse(response, start, total));
|
return this.Ok(generateSlotsResponse(response, start, total));
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,14 +22,16 @@ public class StatisticsController : ControllerBase
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("playersInPodCount")]
|
[HttpGet("playersInPodCount")]
|
||||||
|
public IActionResult PlayersInPodCount() => this.Ok((StatisticsHelper.UserCountInPod(this.database)).ToString());
|
||||||
|
|
||||||
[HttpGet("totalPlayerCount")]
|
[HttpGet("totalPlayerCount")]
|
||||||
public async Task<IActionResult> TotalPlayerCount() => this.Ok((await StatisticsHelper.RecentMatches(this.database)).ToString());
|
public async Task<IActionResult> TotalPlayerCount() => this.Ok((await StatisticsHelper.RecentMatchesForGame(this.database, this.GetToken().GameVersion)).ToString());
|
||||||
|
|
||||||
[HttpGet("planetStats")]
|
[HttpGet("planetStats")]
|
||||||
public async Task<IActionResult> PlanetStats()
|
public async Task<IActionResult> PlanetStats()
|
||||||
{
|
{
|
||||||
int totalSlotCount = await StatisticsHelper.SlotCountForGame(this.database, this.GetToken().GameVersion);
|
int totalSlotCount = await StatisticsHelper.SlotCountForGame(this.database, this.GetToken().GameVersion);
|
||||||
int mmPicksCount = await StatisticsHelper.TeamPickCount(this.database);
|
int mmPicksCount = await StatisticsHelper.TeamPickCountForGame(this.database, this.GetToken().GameVersion);
|
||||||
|
|
||||||
return this.Ok
|
return this.Ok
|
||||||
(
|
(
|
||||||
|
|
|
@ -32,8 +32,8 @@ public abstract class CategoryWithUser : Category
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract IEnumerable<Slot> GetSlots(DatabaseContext database, User user, int pageStart, int pageSize);
|
public abstract IQueryable<Slot> GetSlots(DatabaseContext database, User user, int pageStart, int pageSize);
|
||||||
public override IEnumerable<Slot> GetSlots(DatabaseContext database, int pageStart, int pageSize)
|
public override IList<Slot> GetSlots(DatabaseContext database, int pageStart, int pageSize)
|
||||||
{
|
{
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
Logger.Error("tried to get slots without user on CategoryWithUser", LogArea.Category);
|
Logger.Error("tried to get slots without user on CategoryWithUser", LogArea.Category);
|
||||||
|
|
|
@ -36,7 +36,7 @@ public class CustomCategory : Category
|
||||||
public sealed override string IconHash { get; set; }
|
public sealed override string IconHash { get; set; }
|
||||||
public sealed override string Endpoint { get; set; }
|
public sealed override string Endpoint { get; set; }
|
||||||
public override Slot? GetPreviewSlot(DatabaseContext database) => database.Slots.FirstOrDefault(s => s.SlotId == this.SlotIds[0]);
|
public override Slot? GetPreviewSlot(DatabaseContext database) => database.Slots.FirstOrDefault(s => s.SlotId == this.SlotIds[0]);
|
||||||
public override IEnumerable<Slot> GetSlots
|
public override IQueryable<Slot> GetSlots
|
||||||
(DatabaseContext database, int pageStart, int pageSize)
|
(DatabaseContext database, int pageStart, int pageSize)
|
||||||
=> database.Slots.ByGameVersion(GameVersion.LittleBigPlanet3).Where(s => this.SlotIds.Contains(s.SlotId));
|
=> database.Slots.ByGameVersion(GameVersion.LittleBigPlanet3).Where(s => this.SlotIds.Contains(s.SlotId));
|
||||||
public override int GetTotalSlots(DatabaseContext database) => this.SlotIds.Count;
|
public override int GetTotalSlots(DatabaseContext database) => this.SlotIds.Count;
|
||||||
|
|
|
@ -24,7 +24,7 @@ public class HeartedCategory : CategoryWithUser
|
||||||
.ByGameVersion(GameVersion.LittleBigPlanet3, false, false, true)
|
.ByGameVersion(GameVersion.LittleBigPlanet3, false, false, true)
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
|
|
||||||
public override IEnumerable<Slot> GetSlots(DatabaseContext database, User user, int pageStart, int pageSize)
|
public override IQueryable<Slot> GetSlots(DatabaseContext database, User user, int pageStart, int pageSize)
|
||||||
=> database.HeartedLevels.Where(h => h.UserId == user.UserId)
|
=> database.HeartedLevels.Where(h => h.UserId == user.UserId)
|
||||||
.Where(h => h.Slot.Type == SlotType.User && !h.Slot.Hidden && h.Slot.GameVersion <= GameVersion.LittleBigPlanet3)
|
.Where(h => h.Slot.Type == SlotType.User && !h.Slot.Hidden && h.Slot.GameVersion <= GameVersion.LittleBigPlanet3)
|
||||||
.OrderByDescending(h => h.HeartedLevelId)
|
.OrderByDescending(h => h.HeartedLevelId)
|
||||||
|
|
|
@ -15,7 +15,7 @@ public class LuckyDipCategory : Category
|
||||||
public override string IconHash { get; set; } = "g820605";
|
public override string IconHash { get; set; } = "g820605";
|
||||||
public override string Endpoint { get; set; } = "lbp2luckydip";
|
public override string Endpoint { get; set; } = "lbp2luckydip";
|
||||||
public override Slot? GetPreviewSlot(DatabaseContext database) => database.Slots.Where(s => s.Type == SlotType.User).OrderByDescending(_ => EF.Functions.Random()).FirstOrDefault();
|
public override Slot? GetPreviewSlot(DatabaseContext database) => database.Slots.Where(s => s.Type == SlotType.User).OrderByDescending(_ => EF.Functions.Random()).FirstOrDefault();
|
||||||
public override IEnumerable<Slot> GetSlots
|
public override IQueryable<Slot> GetSlots
|
||||||
(DatabaseContext database, int pageStart, int pageSize)
|
(DatabaseContext database, int pageStart, int pageSize)
|
||||||
=> database.Slots.ByGameVersion(GameVersion.LittleBigPlanet3, false, true)
|
=> database.Slots.ByGameVersion(GameVersion.LittleBigPlanet3, false, true)
|
||||||
.OrderByDescending(_ => EF.Functions.Random())
|
.OrderByDescending(_ => EF.Functions.Random())
|
||||||
|
|
|
@ -18,7 +18,7 @@ public class MostPlayedCategory : Category
|
||||||
.OrderByDescending(s => s.PlaysLBP1Unique + s.PlaysLBP2Unique + s.PlaysLBP3Unique)
|
.OrderByDescending(s => s.PlaysLBP1Unique + s.PlaysLBP2Unique + s.PlaysLBP3Unique)
|
||||||
.ThenByDescending(s => s.PlaysLBP1 + s.PlaysLBP2 + s.PlaysLBP3)
|
.ThenByDescending(s => s.PlaysLBP1 + s.PlaysLBP2 + s.PlaysLBP3)
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
public override IEnumerable<Slot> GetSlots
|
public override IQueryable<Slot> GetSlots
|
||||||
(DatabaseContext database, int pageStart, int pageSize)
|
(DatabaseContext database, int pageStart, int pageSize)
|
||||||
=> database.Slots.ByGameVersion(GameVersion.LittleBigPlanet3, false, true)
|
=> database.Slots.ByGameVersion(GameVersion.LittleBigPlanet3, false, true)
|
||||||
.OrderByDescending(s => s.PlaysLBP1Unique + s.PlaysLBP2Unique + s.PlaysLBP3Unique)
|
.OrderByDescending(s => s.PlaysLBP1Unique + s.PlaysLBP2Unique + s.PlaysLBP3Unique)
|
||||||
|
|
|
@ -14,7 +14,7 @@ public class NewestLevelsCategory : Category
|
||||||
public override string IconHash { get; set; } = "g820623";
|
public override string IconHash { get; set; } = "g820623";
|
||||||
public override string Endpoint { get; set; } = "newest";
|
public override string Endpoint { get; set; } = "newest";
|
||||||
public override Slot? GetPreviewSlot(DatabaseContext database) => database.Slots.Where(s => s.Type == SlotType.User).OrderByDescending(s => s.FirstUploaded).FirstOrDefault();
|
public override Slot? GetPreviewSlot(DatabaseContext database) => database.Slots.Where(s => s.Type == SlotType.User).OrderByDescending(s => s.FirstUploaded).FirstOrDefault();
|
||||||
public override IEnumerable<Slot> GetSlots
|
public override IQueryable<Slot> GetSlots
|
||||||
(DatabaseContext database, int pageStart, int pageSize)
|
(DatabaseContext database, int pageStart, int pageSize)
|
||||||
=> database.Slots.ByGameVersion(GameVersion.LittleBigPlanet3, false, true)
|
=> database.Slots.ByGameVersion(GameVersion.LittleBigPlanet3, false, true)
|
||||||
.OrderByDescending(s => s.FirstUploaded)
|
.OrderByDescending(s => s.FirstUploaded)
|
||||||
|
|
|
@ -24,7 +24,7 @@ public class QueueCategory : CategoryWithUser
|
||||||
.ByGameVersion(GameVersion.LittleBigPlanet3, false, false, true)
|
.ByGameVersion(GameVersion.LittleBigPlanet3, false, false, true)
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
|
|
||||||
public override IEnumerable<Slot> GetSlots(DatabaseContext database, User user, int pageStart, int pageSize)
|
public override IQueryable<Slot> GetSlots(DatabaseContext database, User user, int pageStart, int pageSize)
|
||||||
=> database.QueuedLevels.Where(q => q.UserId == user.UserId)
|
=> database.QueuedLevels.Where(q => q.UserId == user.UserId)
|
||||||
.Where(q => q.Slot.Type == SlotType.User && !q.Slot.Hidden && q.Slot.GameVersion <= GameVersion.LittleBigPlanet3)
|
.Where(q => q.Slot.Type == SlotType.User && !q.Slot.Hidden && q.Slot.GameVersion <= GameVersion.LittleBigPlanet3)
|
||||||
.OrderByDescending(q => q.QueuedLevelId)
|
.OrderByDescending(q => q.QueuedLevelId)
|
||||||
|
|
|
@ -14,7 +14,7 @@ public class TeamPicksCategory : Category
|
||||||
public override string IconHash { get; set; } = "g820626";
|
public override string IconHash { get; set; } = "g820626";
|
||||||
public override string Endpoint { get; set; } = "team_picks";
|
public override string Endpoint { get; set; } = "team_picks";
|
||||||
public override Slot? GetPreviewSlot(DatabaseContext database) => database.Slots.OrderByDescending(s => s.FirstUploaded).FirstOrDefault(s => s.TeamPick);
|
public override Slot? GetPreviewSlot(DatabaseContext database) => database.Slots.OrderByDescending(s => s.FirstUploaded).FirstOrDefault(s => s.TeamPick);
|
||||||
public override IEnumerable<Slot> GetSlots
|
public override IQueryable<Slot> GetSlots
|
||||||
(DatabaseContext database, int pageStart, int pageSize)
|
(DatabaseContext database, int pageStart, int pageSize)
|
||||||
=> database.Slots.ByGameVersion(GameVersion.LittleBigPlanet3, false, true)
|
=> database.Slots.ByGameVersion(GameVersion.LittleBigPlanet3, false, true)
|
||||||
.OrderByDescending(s => s.FirstUploaded)
|
.OrderByDescending(s => s.FirstUploaded)
|
||||||
|
|
|
@ -3,6 +3,7 @@ using System.Threading.Tasks;
|
||||||
using LBPUnion.ProjectLighthouse.Database;
|
using LBPUnion.ProjectLighthouse.Database;
|
||||||
using LBPUnion.ProjectLighthouse.Extensions;
|
using LBPUnion.ProjectLighthouse.Extensions;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||||
|
using LBPUnion.ProjectLighthouse.Types.Matchmaking.Rooms;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Users;
|
using LBPUnion.ProjectLighthouse.Types.Users;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
@ -22,8 +23,12 @@ public static class StatisticsHelper
|
||||||
|
|
||||||
public static async Task<int> UserCount(DatabaseContext database) => await database.Users.CountAsync(u => u.PermissionLevel != PermissionLevel.Banned);
|
public static async Task<int> UserCount(DatabaseContext database) => await database.Users.CountAsync(u => u.PermissionLevel != PermissionLevel.Banned);
|
||||||
|
|
||||||
|
public static int UserCountInPod(DatabaseContext database) => RoomHelper.Rooms.Count(r => r.State == RoomState.Idle);
|
||||||
|
|
||||||
public static async Task<int> TeamPickCount(DatabaseContext database) => await database.Slots.CountAsync(s => s.TeamPick);
|
public static async Task<int> TeamPickCount(DatabaseContext database) => await database.Slots.CountAsync(s => s.TeamPick);
|
||||||
|
|
||||||
|
public static async Task<int> TeamPickCountForGame(DatabaseContext database, GameVersion gameVersion) => await database.Slots.ByGameVersion(gameVersion).CountAsync(s => s.TeamPick);
|
||||||
|
|
||||||
public static async Task<int> PhotoCount(DatabaseContext database) => await database.Photos.CountAsync();
|
public static async Task<int> PhotoCount(DatabaseContext database) => await database.Photos.CountAsync();
|
||||||
|
|
||||||
#region Moderator/Admin specific
|
#region Moderator/Admin specific
|
||||||
|
|
|
@ -163,7 +163,6 @@ public class Slot
|
||||||
|
|
||||||
[XmlIgnore]
|
[XmlIgnore]
|
||||||
public bool TeamPick { get; set; }
|
public bool TeamPick { get; set; }
|
||||||
|
|
||||||
[XmlIgnore]
|
[XmlIgnore]
|
||||||
public GameVersion GameVersion { get; set; }
|
public GameVersion GameVersion { get; set; }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue