🐛 Session auto renew

This commit is contained in:
2025-09-13 16:33:43 +08:00
parent be6d97ec85
commit 19bf17200d

View File

@@ -42,8 +42,17 @@ public class LastActiveFlushHandler(IServiceProvider srp, ILogger<LastActiveFlus
var updatingSessions = sessionMap.Select(x => x.Key).ToList(); var updatingSessions = sessionMap.Select(x => x.Key).ToList();
var sessionUpdates = await db.AuthSessions var sessionUpdates = await db.AuthSessions
.Where(s => updatingSessions.Contains(s.Id)) .Where(s => updatingSessions.Contains(s.Id))
.ExecuteUpdateAsync(s => s.SetProperty(x => x.LastGrantedAt, now)); .ExecuteUpdateAsync(s =>
s.SetProperty(x => x.LastGrantedAt, now)
);
logger.LogInformation("Updated {Count} auth sessions according to LastActiveInfo", sessionUpdates); logger.LogInformation("Updated {Count} auth sessions according to LastActiveInfo", sessionUpdates);
var newExpiration = now.Plus(Duration.FromDays(7));
var keepAliveSessionUpdates = await db.AuthSessions
.Where(s => updatingSessions.Contains(s.Id) && s.ExpiredAt != null)
.ExecuteUpdateAsync(s =>
s.SetProperty(x => x.ExpiredAt, newExpiration)
);
logger.LogInformation("Updated {Count} auth sessions' duration according to LastActiveInfo", sessionUpdates);
var updatingAccounts = accountMap.Select(x => x.Key).ToList(); var updatingAccounts = accountMap.Select(x => x.Key).ToList();
var profileUpdates = await db.AccountProfiles var profileUpdates = await db.AccountProfiles
@@ -53,7 +62,8 @@ public class LastActiveFlushHandler(IServiceProvider srp, ILogger<LastActiveFlus
} }
} }
public class LastActiveFlushJob(FlushBufferService fbs, LastActiveFlushHandler hdl, ILogger<LastActiveFlushJob> logger) : IJob public class LastActiveFlushJob(FlushBufferService fbs, LastActiveFlushHandler hdl, ILogger<LastActiveFlushJob> logger)
: IJob
{ {
public async Task Execute(IJobExecutionContext context) public async Task Execute(IJobExecutionContext context)
{ {
@@ -62,7 +72,8 @@ public class LastActiveFlushJob(FlushBufferService fbs, LastActiveFlushHandler h
logger.LogInformation("Running LastActiveInfo flush job..."); logger.LogInformation("Running LastActiveInfo flush job...");
await fbs.FlushAsync(hdl); await fbs.FlushAsync(hdl);
logger.LogInformation("Completed LastActiveInfo flush job..."); logger.LogInformation("Completed LastActiveInfo flush job...");
} catch (Exception ex) }
catch (Exception ex)
{ {
logger.LogError(ex, "Error running LastActiveInfo job..."); logger.LogError(ex, "Error running LastActiveInfo job...");
} }