feat(collection): replace paginated collection browser with full owned map
Adds collection.get_owned endpoint that returns { definitionId → count }
for the player's entire collection in a single DB round-trip. The client
caches this map and filters/sorts entirely client-side using definitions
already in ContentCache, eliminating all pagination and "load more" UI.
- Search, type, and affinity filters now work across the full collection
instantly with no network round-trips
- deck_editor_panel: arch spirit picker also uses the owned map —
removes a separate collection.get_cards request
- cards_view: same pattern, grid rebuilds client-side on filter change
- CollectionCache: persists owned map to disk (owned.json per player)
Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -2,6 +2,12 @@ namespace SOR.Collection;
|
||||
|
||||
// ── Request types (client → server) ──────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// Returns the full owned collection as { definitionId → ownedCount }.
|
||||
/// No pagination — the map is small and enables client-side filter/sort.
|
||||
/// </summary>
|
||||
public sealed record GetOwnedRequest; // identity from connection
|
||||
|
||||
/// <summary>
|
||||
/// Paginated list of all cards the authenticated player owns.
|
||||
/// NameFilter: case-insensitive substring match on card name (optional).
|
||||
@@ -75,6 +81,8 @@ public sealed record SelectStarterDeckRequest(Guid StarterDeckId);
|
||||
|
||||
// ── Response / DTO types (server → client) ────────────────────────────────────
|
||||
|
||||
public sealed record GetOwnedResponse(Dictionary<Guid, int> Owned);
|
||||
|
||||
public sealed record GetCardsResponse(
|
||||
IEnumerable<PlayerCardDto> Cards,
|
||||
int TotalCount,
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
namespace SOR.Collection.Handlers;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SOR.Database.Contexts;
|
||||
using SOR.Networking.Abstractions.Messaging;
|
||||
using SOR.Networking.Abstractions.Transport;
|
||||
using SOR.Shared.Networking;
|
||||
|
||||
/// <summary>
|
||||
/// collection.get_owned — returns the full owned collection as { definitionId → ownedCount }.
|
||||
///
|
||||
/// No pagination: the map is small (one entry per unique card definition owned)
|
||||
/// and returning it all at once lets the client filter and sort without round-trips.
|
||||
/// </summary>
|
||||
internal sealed class CollectionGetOwnedHandler : CollectionHandlerBase, IMessageHandler
|
||||
{
|
||||
private readonly CollectionDbContext _collectionDb;
|
||||
|
||||
public CollectionGetOwnedHandler(CollectionDbContext collectionDb)
|
||||
=> _collectionDb = collectionDb;
|
||||
|
||||
public string MessageType => "collection.get_owned";
|
||||
|
||||
public async Task<IServerMessage?> HandleAsync(
|
||||
IClientMessage message,
|
||||
AuthenticatedConnection connection,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var accountId = Guid.Parse(connection.UserId);
|
||||
|
||||
var owned = await _collectionDb.PlayerCards
|
||||
.Where(pc => pc.AccountId == accountId)
|
||||
.GroupBy(pc => pc.CardDefinitionId)
|
||||
.Select(g => new { DefId = g.Key, Count = g.Count() })
|
||||
.ToDictionaryAsync(x => x.DefId, x => x.Count, cancellationToken);
|
||||
|
||||
return ServerMessage.Reply(
|
||||
"collection.get_owned.ack",
|
||||
message.Seq,
|
||||
new GetOwnedResponse(owned));
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ public static class ServiceRegistration
|
||||
// Message handlers — one per message type, Transient lifetime.
|
||||
// MessageDispatcher collects all IMessageHandler registrations at startup.
|
||||
services.AddTransient<IMessageHandler, CollectionGetCardsHandler>();
|
||||
services.AddTransient<IMessageHandler, CollectionGetOwnedHandler>();
|
||||
services.AddTransient<IMessageHandler, CollectionGetDecksHandler>();
|
||||
services.AddTransient<IMessageHandler, CollectionGetDeckHandler>();
|
||||
services.AddTransient<IMessageHandler, CollectionCreateDeckHandler>();
|
||||
|
||||
Reference in New Issue
Block a user