MCPcopy Create free account
hub / github.com/TryCatchLearn/Overflow / TopUsersProjection

Class TopUsersProjection

StatsService/Projections/TopUsersProjection.cs:9–33  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7namespace StatsService.Projections;
8
9public class TopUsersProjection : EventProjection
10{
11 public TopUsersProjection() => ProjectAsync<IEvent<UserReputationChanged>>(Apply);
12
13 private static async Task Apply(IEvent<UserReputationChanged> ev, IDocumentOperations ops, CancellationToken ct)
14 {
15 var day = DateOnly.FromDateTime(ev.Timestamp.UtcDateTime);
16
17 var data = ev.Data;
18
19 var id = $"{data.UserId}:{day:yyyy-MM-dd}";
20
21 var doc = await ops.LoadAsync<UserDailyReputation>(id, ct)
22 ?? new UserDailyReputation
23 {
24 Id = id,
25 UserId = data.UserId,
26 Date = day,
27 Delta = 0
28 };
29
30 doc.Delta += data.Delta;
31 ops.Store(doc);
32 }
33}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…