perf: optimize authorization scoreline and workers

This commit is contained in:
2026-07-30 09:12:27 +08:00
parent 4bea745b79
commit bedc77bffd
52 changed files with 21911 additions and 347 deletions

View File

@@ -0,0 +1,24 @@
namespace Tiku.Application.Auth;
public interface IRequestSecurityState
{
AuthSessionValidationResult? ValidatedSession { get; }
void SetValidatedSession(AuthSessionValidationResult session);
}
internal sealed class RequestSecurityState : IRequestSecurityState
{
public AuthSessionValidationResult? ValidatedSession { get; private set; }
public void SetValidatedSession(AuthSessionValidationResult session)
{
ArgumentNullException.ThrowIfNull(session);
if (ValidatedSession is not null && ValidatedSession != session)
{
throw new InvalidOperationException("The request security session was already initialized.");
}
ValidatedSession = session;
}
}

View File

@@ -1,5 +1,6 @@
using Microsoft.Extensions.DependencyInjection;
using Tiku.Application.Security;
using Tiku.Application.Auth;
namespace Tiku.Application;
@@ -8,6 +9,7 @@ public static class DependencyInjection
public static IServiceCollection AddApplication(this IServiceCollection services)
{
services.AddScoped<ICurrentUser, CurrentUser>();
services.AddScoped<IRequestSecurityState, RequestSecurityState>();
services.AddScoped<TenantContext>();
services.AddScoped<ITenantContext>(provider => provider.GetRequiredService<TenantContext>());
services.AddScoped<ITenantContextInitializer>(provider => provider.GetRequiredService<TenantContext>());

View File

@@ -51,10 +51,17 @@ public sealed record ScorelineRecordPage(
int Total,
IReadOnlyCollection<ScorelineRecordItem> Items);
public sealed record ScorelineRecordCursorPage(
int PageSize,
bool HasMore,
string? NextCursor,
IReadOnlyCollection<ScorelineRecordItem> Items);
public interface IScorelineQueryService
{
Task<CatalogList<ScorelineFieldItem>> GetFieldsAsync(ScorelineFilter filter, CancellationToken cancellationToken = default);
Task<ScorelineRecordPage> GetRecordsAsync(ScorelineFilter filter, CancellationToken cancellationToken = default);
Task<ScorelineRecordCursorPage> GetRecordsCursorAsync(ScorelineFilter filter, string? cursor, CancellationToken cancellationToken = default);
Task<CatalogList<ScorelineRecordItem>> GetTrendAsync(ScorelineFilter filter, CancellationToken cancellationToken = default);
Task<CatalogList<int>> GetYearsAsync(ScorelineFilter filter, CancellationToken cancellationToken = default);
}

View File

@@ -0,0 +1,6 @@
namespace Tiku.Application.Security;
public interface ITenantFeatureCacheInvalidator
{
Task InvalidateAsync(Guid tenantId, CancellationToken cancellationToken = default);
}

View File

@@ -0,0 +1,6 @@
namespace Tiku.Application.Tenancy;
public interface ITenantPublicCacheInvalidator
{
Task InvalidateAsync(Guid tenantId, CancellationToken cancellationToken = default);
}

View File

@@ -35,5 +35,5 @@ public interface ITenantDomainLifecycleService
public interface ITenantRuntimeCacheInvalidator
{
void Invalidate(Guid tenantId);
Task InvalidateAsync(Guid tenantId, CancellationToken cancellationToken = default);
}