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:
W0lf4llo 2023-03-16 23:51:55 -04:00 committed by GitHub
parent 14e40de18f
commit 9b014fa01c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 19 additions and 13 deletions

View file

@ -280,7 +280,7 @@ public class SlotsController : ControllerBase
.Take(Math.Min(pageSize, 30));
string response = Enumerable.Aggregate(slots, string.Empty, (current, slot) => current + slot.Serialize(gameVersion));
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));
}

View file

@ -22,14 +22,16 @@ public class StatisticsController : ControllerBase
}
[HttpGet("playersInPodCount")]
public IActionResult PlayersInPodCount() => this.Ok((StatisticsHelper.UserCountInPod(this.database)).ToString());
[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")]
public async Task<IActionResult> PlanetStats()
{
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
(

View file

@ -32,8 +32,8 @@ public abstract class CategoryWithUser : Category
return -1;
}
public abstract IEnumerable<Slot> GetSlots(DatabaseContext database, User user, int pageStart, int pageSize);
public override IEnumerable<Slot> GetSlots(DatabaseContext database, int pageStart, int pageSize)
public abstract IQueryable<Slot> GetSlots(DatabaseContext database, User user, int pageStart, int pageSize);
public override IList<Slot> GetSlots(DatabaseContext database, int pageStart, int pageSize)
{
#if DEBUG
Logger.Error("tried to get slots without user on CategoryWithUser", LogArea.Category);

View file

@ -36,7 +36,7 @@ public class CustomCategory : Category
public sealed override string IconHash { 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 IEnumerable<Slot> GetSlots
public override IQueryable<Slot> GetSlots
(DatabaseContext database, int pageStart, int pageSize)
=> database.Slots.ByGameVersion(GameVersion.LittleBigPlanet3).Where(s => this.SlotIds.Contains(s.SlotId));
public override int GetTotalSlots(DatabaseContext database) => this.SlotIds.Count;

View file

@ -24,7 +24,7 @@ public class HeartedCategory : CategoryWithUser
.ByGameVersion(GameVersion.LittleBigPlanet3, false, false, true)
.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)
.Where(h => h.Slot.Type == SlotType.User && !h.Slot.Hidden && h.Slot.GameVersion <= GameVersion.LittleBigPlanet3)
.OrderByDescending(h => h.HeartedLevelId)

View file

@ -15,7 +15,7 @@ public class LuckyDipCategory : Category
public override string IconHash { get; set; } = "g820605";
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 IEnumerable<Slot> GetSlots
public override IQueryable<Slot> GetSlots
(DatabaseContext database, int pageStart, int pageSize)
=> database.Slots.ByGameVersion(GameVersion.LittleBigPlanet3, false, true)
.OrderByDescending(_ => EF.Functions.Random())

View file

@ -18,7 +18,7 @@ public class MostPlayedCategory : Category
.OrderByDescending(s => s.PlaysLBP1Unique + s.PlaysLBP2Unique + s.PlaysLBP3Unique)
.ThenByDescending(s => s.PlaysLBP1 + s.PlaysLBP2 + s.PlaysLBP3)
.FirstOrDefault();
public override IEnumerable<Slot> GetSlots
public override IQueryable<Slot> GetSlots
(DatabaseContext database, int pageStart, int pageSize)
=> database.Slots.ByGameVersion(GameVersion.LittleBigPlanet3, false, true)
.OrderByDescending(s => s.PlaysLBP1Unique + s.PlaysLBP2Unique + s.PlaysLBP3Unique)

View file

@ -14,7 +14,7 @@ public class NewestLevelsCategory : Category
public override string IconHash { get; set; } = "g820623";
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 IEnumerable<Slot> GetSlots
public override IQueryable<Slot> GetSlots
(DatabaseContext database, int pageStart, int pageSize)
=> database.Slots.ByGameVersion(GameVersion.LittleBigPlanet3, false, true)
.OrderByDescending(s => s.FirstUploaded)

View file

@ -24,7 +24,7 @@ public class QueueCategory : CategoryWithUser
.ByGameVersion(GameVersion.LittleBigPlanet3, false, false, true)
.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)
.Where(q => q.Slot.Type == SlotType.User && !q.Slot.Hidden && q.Slot.GameVersion <= GameVersion.LittleBigPlanet3)
.OrderByDescending(q => q.QueuedLevelId)

View file

@ -14,7 +14,7 @@ public class TeamPicksCategory : Category
public override string IconHash { get; set; } = "g820626";
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 IEnumerable<Slot> GetSlots
public override IQueryable<Slot> GetSlots
(DatabaseContext database, int pageStart, int pageSize)
=> database.Slots.ByGameVersion(GameVersion.LittleBigPlanet3, false, true)
.OrderByDescending(s => s.FirstUploaded)

View file

@ -3,6 +3,7 @@ using System.Threading.Tasks;
using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Extensions;
using LBPUnion.ProjectLighthouse.Types.Levels;
using LBPUnion.ProjectLighthouse.Types.Matchmaking.Rooms;
using LBPUnion.ProjectLighthouse.Types.Users;
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 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> 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();
#region Moderator/Admin specific

View file

@ -163,7 +163,6 @@ public class Slot
[XmlIgnore]
public bool TeamPick { get; set; }
[XmlIgnore]
public GameVersion GameVersion { get; set; }