Fix delet syncshell
This commit is contained in:
@@ -80,7 +80,7 @@ public partial class MareHub : Hub<IMareHub>, IMareHub
|
|||||||
dbUser.LastLoggedIn = DateTime.UtcNow;
|
dbUser.LastLoggedIn = DateTime.UtcNow;
|
||||||
await DbContext.SaveChangesAsync().ConfigureAwait(false);
|
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))
|
return new ConnectionDto(new UserData(dbUser.UID, string.IsNullOrWhiteSpace(dbUser.Alias) ? null : dbUser.Alias))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using MareSynchronosShared.Services;
|
|||||||
using MareSynchronosShared.Utils;
|
using MareSynchronosShared.Utils;
|
||||||
using MareSynchronosShared.Utils.Configuration;
|
using MareSynchronosShared.Utils.Configuration;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace MareSynchronosServer.Services;
|
namespace MareSynchronosServer.Services;
|
||||||
|
|
||||||
@@ -46,20 +47,41 @@ public class UserCleanupService : IHostedService
|
|||||||
await PurgeUnusedAccounts(dbContext).ConfigureAwait(false);
|
await PurgeUnusedAccounts(dbContext).ConfigureAwait(false);
|
||||||
|
|
||||||
await PurgeTempInvites(dbContext).ConfigureAwait(false);
|
await PurgeTempInvites(dbContext).ConfigureAwait(false);
|
||||||
|
await PurgeExpiredTemporaryGroups(dbContext).ConfigureAwait(false);
|
||||||
|
|
||||||
dbContext.SaveChanges();
|
dbContext.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
var now = DateTime.Now;
|
var span = TimeSpan.FromMinutes(1);
|
||||||
TimeOnly currentTime = new(now.Hour, now.Minute, now.Second);
|
var nextRun = DateTime.Now.Add(span);
|
||||||
TimeOnly futureTime = new(now.Hour, now.Minute - now.Minute % 10, 0);
|
|
||||||
var span = futureTime.AddMinutes(10) - currentTime;
|
|
||||||
|
|
||||||
_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);
|
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)
|
private async Task PurgeTempInvites(MareDbContext dbContext)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
Reference in New Issue
Block a user