:drunk: No idea what did AI did
This commit is contained in:
@ -4,16 +4,11 @@ using Quartz;
|
||||
using DysonNetwork.Drive.Auth;
|
||||
using DysonNetwork.Drive.Models;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using DysonNetwork.Common.Models;
|
||||
using System;
|
||||
|
||||
namespace DysonNetwork.Drive.Handlers;
|
||||
|
||||
public class LastActiveInfo
|
||||
{
|
||||
public Session Session { get; set; } = null!;
|
||||
public Account Account { get; set; } = null!;
|
||||
public Instant SeenAt { get; set; }
|
||||
}
|
||||
|
||||
public class LastActiveFlushHandler(IServiceProvider serviceProvider) : IFlushHandler<LastActiveInfo>
|
||||
{
|
||||
public async Task FlushAsync(IReadOnlyList<LastActiveInfo> items)
|
||||
@ -23,18 +18,18 @@ public class LastActiveFlushHandler(IServiceProvider serviceProvider) : IFlushHa
|
||||
|
||||
// Remove duplicates by grouping on (sessionId, accountId), taking the most recent SeenAt
|
||||
var distinctItems = items
|
||||
.GroupBy(x => (SessionId: x.Session.Id, AccountId: x.Account.Id))
|
||||
.GroupBy(x => (SessionId: x.SessionId, AccountId: x.AccountId))
|
||||
.Select(g => g.OrderByDescending(x => x.SeenAt).First())
|
||||
.ToList();
|
||||
|
||||
// Build dictionaries so we can match session/account IDs to their new "last seen" timestamps
|
||||
var sessionIdMap = distinctItems
|
||||
.GroupBy(x => x.SessionId)
|
||||
.ToDictionary(g => g.Key, g => g.Last().SeenAt);
|
||||
.ToDictionary(g => Guid.Parse(g.Key), g => g.Last().SeenAt);
|
||||
|
||||
var accountIdMap = distinctItems
|
||||
.GroupBy(x => x.AccountId)
|
||||
.ToDictionary(g => g.Key, g => g.Last().SeenAt);
|
||||
.ToDictionary(g => Guid.Parse(g.Key), g => g.Last().SeenAt);
|
||||
|
||||
// Update sessions using native EF Core ExecuteUpdateAsync
|
||||
foreach (var kvp in sessionIdMap)
|
||||
|
Reference in New Issue
Block a user