forked from gongxuegit/tiku-backend.net
perf: optimize authorization scoreline and workers
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.OutputCaching;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Tiku.Application.Assets;
|
||||
using Tiku.Api.Contracts;
|
||||
@@ -18,6 +19,7 @@ namespace Tiku.Api.Controllers;
|
||||
[AllowAnonymous]
|
||||
[Produces("application/json")]
|
||||
[Route("api/catalog")]
|
||||
[OutputCache(PolicyName = "TenantPublic")]
|
||||
public sealed class CatalogController(
|
||||
ICatalogQueryService catalogQueryService,
|
||||
IContentNavigationQueryService contentNavigationQueryService,
|
||||
|
||||
@@ -4,9 +4,9 @@ using Tiku.Api.Contracts;
|
||||
using Tiku.Application.Security;
|
||||
using Tiku.Infrastructure.Persistence;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using MassTransit.EntityFrameworkCoreIntegration;
|
||||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||
using Tiku.Infrastructure.Messaging;
|
||||
using Tiku.Api.Observability;
|
||||
|
||||
namespace Tiku.Api.Controllers;
|
||||
|
||||
@@ -19,7 +19,8 @@ public sealed class HealthController(
|
||||
TikuDbContext dbContext,
|
||||
IRedisSecurityStore redisSecurityStore,
|
||||
MessagingOptions messagingOptions,
|
||||
HealthCheckService healthCheckService) : ControllerBase
|
||||
HealthCheckService healthCheckService,
|
||||
OutboxBacklogSnapshot outboxSnapshot) : ControllerBase
|
||||
{
|
||||
[HttpGet]
|
||||
[EndpointSummary("健康检查")]
|
||||
@@ -43,17 +44,8 @@ public sealed class HealthController(
|
||||
registration => registration.Tags.Contains("ready"),
|
||||
cancellationToken);
|
||||
var rabbitMq = !messagingOptions.IsConfigured || rabbitHealth.Status == HealthStatus.Healthy;
|
||||
var outboxPending = database
|
||||
? await dbContext.Set<OutboxMessage>().CountAsync(cancellationToken)
|
||||
: -1;
|
||||
var outboxOldestSentTime = database
|
||||
? await dbContext.Set<OutboxMessage>()
|
||||
.Select(message => (DateTime?)message.SentTime)
|
||||
.MinAsync(cancellationToken)
|
||||
: null;
|
||||
var outboxOldestAgeSeconds = outboxOldestSentTime is null
|
||||
? 0
|
||||
: Math.Max(0, (DateTimeOffset.UtcNow - new DateTimeOffset(outboxOldestSentTime.Value)).TotalSeconds);
|
||||
var outboxPending = outboxSnapshot.Pending;
|
||||
var outboxOldestAgeSeconds = outboxSnapshot.OldestAgeSeconds;
|
||||
var outboxAlert = outboxPending >= messagingOptions.OutboxBacklogAlertCount ||
|
||||
outboxOldestAgeSeconds >= messagingOptions.OutboxOldestMessageAlertSeconds;
|
||||
var ready = database && redis && rabbitMq;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.OutputCaching;
|
||||
using Tiku.Application.Security;
|
||||
using Tiku.Application.Tenancy;
|
||||
|
||||
@@ -15,6 +16,7 @@ public sealed class RuntimeController(
|
||||
ITenantFrontendConfigService frontendConfigService) : ControllerBase
|
||||
{
|
||||
[HttpGet("bootstrap")]
|
||||
[OutputCache(PolicyName = "TenantPublic")]
|
||||
[EndpointSummary("获取租户前端运行时配置")]
|
||||
[ProducesResponseType<TenantRuntimeBootstrap>(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status304NotModified)]
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.OutputCaching;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Tiku.Api.Contracts;
|
||||
using Tiku.Application.Catalog;
|
||||
@@ -24,6 +25,7 @@ public sealed class ScorelineController(
|
||||
private static readonly string[] DynamicPrefixes = ["field.", "min.", "max."];
|
||||
|
||||
[HttpGet("fields")]
|
||||
[OutputCache(PolicyName = "TenantPublic")]
|
||||
[EndpointSummary("查询分数线字段配置")]
|
||||
[ProducesResponseType<CatalogList<ScorelineFieldItem>>(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType<ProblemDetails>(StatusCodes.Status404NotFound)]
|
||||
@@ -49,6 +51,20 @@ public sealed class ScorelineController(
|
||||
cancellationToken));
|
||||
}
|
||||
|
||||
[HttpGet("records/cursor")]
|
||||
[EndpointSummary("游标分页查询分数线记录")]
|
||||
[ProducesResponseType<ScorelineRecordCursorPage>(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType<ProblemDetails>(StatusCodes.Status400BadRequest)]
|
||||
public async Task<ActionResult<ScorelineRecordCursorPage>> GetRecordsCursor(
|
||||
[FromQuery] ScorelineQueryDto query,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
return Ok(await scorelineQueryService.GetRecordsCursorAsync(
|
||||
query.ToFilter(await ResolveTenantIdAsync(query, cancellationToken), ResolveDynamicFilters()),
|
||||
query.Cursor,
|
||||
cancellationToken));
|
||||
}
|
||||
|
||||
[HttpGet("trend")]
|
||||
[EndpointSummary("查询历年分数线趋势")]
|
||||
[ProducesResponseType<CatalogList<ScorelineRecordItem>>(StatusCodes.Status200OK)]
|
||||
@@ -63,6 +79,7 @@ public sealed class ScorelineController(
|
||||
}
|
||||
|
||||
[HttpGet("years")]
|
||||
[OutputCache(PolicyName = "TenantPublic")]
|
||||
[EndpointSummary("查询分数线可用年份")]
|
||||
[ProducesResponseType<CatalogList<int>>(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType<ProblemDetails>(StatusCodes.Status404NotFound)]
|
||||
|
||||
Reference in New Issue
Block a user