From 00a9bd00e5cbafde7f7d553f4f4a435b5475f01d Mon Sep 17 00:00:00 2001 From: ccnetcore Date: Wed, 7 Jan 2026 20:10:42 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E8=B0=83=E6=95=B4=E5=85=AC=E5=91=8A?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E4=B8=8E=E6=8E=92=E5=BA=8F=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=8C=E4=BC=98=E5=8C=96=E6=9C=89=E6=95=88=E5=85=AC=E5=91=8A?= =?UTF-8?q?=E4=BC=98=E5=85=88=E7=BA=A7=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/AnnouncementService.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/AnnouncementService.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/AnnouncementService.cs index 2399070e..a1001148 100644 --- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/AnnouncementService.cs +++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/AnnouncementService.cs @@ -53,13 +53,23 @@ public class AnnouncementService : ApplicationService, IAnnouncementService /// private async Task LoadAnnouncementDataAsync() { - // 查询所有公告日志,按日期降序排列 + // 1️⃣ 一次性查出全部公告(不排序) var logs = await _announcementRepository._DbQueryable - .OrderByDescending(x => x.StartTime) .ToListAsync(); + var now = DateTime.Now; + + // 2️⃣ 内存中处理排序 + var orderedLogs = logs + .OrderByDescending(x => + x.StartTime <= now && + (x.EndTime == null || x.EndTime >= now) + ) + .ThenByDescending(x => x.StartTime) + .ToList(); + // 转换为 DTO - var logDtos = logs.Adapt>(); + var logDtos = orderedLogs.Adapt>(); return new AnnouncementCacheDto { Logs = logDtos