Fix delet syncshell

This commit is contained in:
2025-09-20 12:13:45 +02:00
parent 79ff8fad7a
commit cd5248e4e6
2 changed files with 28 additions and 6 deletions

View File

@@ -80,7 +80,7 @@ public partial class MareHub : Hub<IMareHub>, IMareHub
dbUser.LastLoggedIn = DateTime.UtcNow;
await DbContext.SaveChangesAsync().ConfigureAwait(false);
await Clients.Caller.Client_ReceiveServerMessage(MessageSeverity.Information, "Welcome to Umbra! Current Online Users: " + _systemInfoService.SystemInfoDto.OnlineUsers).ConfigureAwait(false);
await Clients.Caller.Client_ReceiveServerMessage(MessageSeverity.Information, "Bienvenue sur UmbraSync ! Utilisateurs en ligne : " + _systemInfoService.SystemInfoDto.OnlineUsers).ConfigureAwait(false);
return new ConnectionDto(new UserData(dbUser.UID, string.IsNullOrWhiteSpace(dbUser.Alias) ? null : dbUser.Alias))
{

View File

@@ -5,6 +5,7 @@ using MareSynchronosShared.Services;
using MareSynchronosShared.Utils;
using MareSynchronosShared.Utils.Configuration;
using Microsoft.EntityFrameworkCore;
using System.Linq;
namespace MareSynchronosServer.Services;
@@ -46,20 +47,41 @@ public class UserCleanupService : IHostedService
await PurgeUnusedAccounts(dbContext).ConfigureAwait(false);
await PurgeTempInvites(dbContext).ConfigureAwait(false);
await PurgeExpiredTemporaryGroups(dbContext).ConfigureAwait(false);
dbContext.SaveChanges();
}
var now = DateTime.Now;
TimeOnly currentTime = new(now.Hour, now.Minute, now.Second);
TimeOnly futureTime = new(now.Hour, now.Minute - now.Minute % 10, 0);
var span = futureTime.AddMinutes(10) - currentTime;
var span = TimeSpan.FromMinutes(1);
var nextRun = DateTime.Now.Add(span);
_logger.LogInformation("User Cleanup Complete, next run at {date}", now.Add(span));
_logger.LogInformation("User Cleanup Complete, next run at {date}", nextRun);
await Task.Delay(span, ct).ConfigureAwait(false);
}
}
private async Task PurgeExpiredTemporaryGroups(MareDbContext dbContext)
{
try
{
var now = DateTime.UtcNow;
var expiredGroups = await dbContext.Groups
.Where(g => g.IsTemporary && g.ExpiresAt != null && g.ExpiresAt <= now)
.ToListAsync()
.ConfigureAwait(false);
if (expiredGroups.Count == 0) return;
_logger.LogInformation("Cleaning up {count} expired temporary syncshells", expiredGroups.Count);
dbContext.Groups.RemoveRange(expiredGroups);
}
catch (Exception ex)
{
_logger.LogWarning(ex, "Error during temporary syncshell purge");
}
}
private async Task PurgeTempInvites(MareDbContext dbContext)
{
try