From 4373c23ff45aac0a7fc441d0452c6590eef09b9c Mon Sep 17 00:00:00 2001 From: jvyden Date: Wed, 10 Nov 2021 00:29:43 -0500 Subject: [PATCH] Lucky dip improvements --- ProjectLighthouse/Controllers/SlotsController.cs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/ProjectLighthouse/Controllers/SlotsController.cs b/ProjectLighthouse/Controllers/SlotsController.cs index b8591722..2a01f5fc 100644 --- a/ProjectLighthouse/Controllers/SlotsController.cs +++ b/ProjectLighthouse/Controllers/SlotsController.cs @@ -1,5 +1,6 @@ #nullable enable using System; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using LBPUnion.ProjectLighthouse.Serialization; @@ -115,15 +116,19 @@ namespace LBPUnion.ProjectLighthouse.Controllers if (token == null) return this.BadRequest(); GameVersion gameVersion = token.GameVersion; + int slotCount = await this.database.Slots.Where(s => s.GameVersion <= gameVersion).CountAsync(); + pageSize = Math.Min(pageSize, 30); + + int skipCount = new Random().Next(seed, slotCount) + pageStart - 1; // TODO: Incorporate seed? - IOrderedEnumerable slots = this.database.Slots.Where(s => s.GameVersion <= gameVersion) + IEnumerable slots = this.database.Slots.Where(s => s.GameVersion <= gameVersion) .Include(s => s.Creator) .Include(s => s.Location) - .Skip(pageStart - 1) - .Take(Math.Min(pageSize, 30)) - .AsEnumerable() - .OrderBy(_ => Guid.NewGuid()); + .Skip(skipCount) + .Take(pageSize) + .AsEnumerable(); + string response = slots.Aggregate(string.Empty, (current, slot) => current + slot.Serialize()); return this.Ok(LbpSerializer.TaggedStringElement("slots", response, "hint_start", pageStart + Math.Min(pageSize, 30)));