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>
43 lines
1.5 KiB
C#
43 lines
1.5 KiB
C#
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));
|
|
}
|
|
}
|