Files
Artemy 6d1c53beeb Refactor: migrate Core -> Domain and reorganize projects
Large refactor that renames/moves core types into a new Govor.Domain surface and reorganizes the Application layer. Models, configurations, migrations and many files moved from Govor.Core/Govor.Data to Govor.Domain; numerous Application services, interfaces and implementations were relocated or added (authentication, friends, messages, medias, push notifications, user sessions, storage, synching, private chats, etc.). Tests updated to use Govor.Domain namespaces and adjusted project references (removed Govor.Data reference from API tests). Also updated API, Hub and mapping code and project files to reflect the new structure and naming. This is primarily a codebase-wide namespace and module reorganization to establish a Domain project and restructure application services.
2026-07-16 19:27:45 +07:00

33 lines
994 B
C#

using Govor.Domain;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Caching.Memory;
namespace Govor.Application.PingHandler;
public class PingHandlerService : IPingHandlerService
{
private readonly GovorDbContext _context;
private readonly IMemoryCache _cache;
public PingHandlerService(GovorDbContext context, IMemoryCache cache)
{
_context = context;
_cache = cache;
}
public async Task Ping(Guid userId)
{
var cacheKey = $"LastPing_{userId}";
if (_cache.TryGetValue(cacheKey, out DateTime lastPing) &&
DateTime.UtcNow.Subtract(lastPing).TotalSeconds < 30)
{
return; // Пропускаем слишком частые пинги
}
await _context.Users
.Where(u => u.Id == userId)
.ExecuteUpdateAsync(u => u.SetProperty(x => x.WasOnline, DateTime.UtcNow));
_cache.Set(cacheKey, DateTime.UtcNow, TimeSpan.FromSeconds(30));
}
}