给统计缓存加版本并绑定现有基础数据/课表失效标签,同时让演示数据、人员数据写入主动清理统计缓存;不改统计口径、筛选、导出或页面结构。

This commit is contained in:
2026-07-26 21:32:51 +08:00 Unverified
parent 034f1eacb8
commit b39a57ebdf
7 changed files with 35 additions and 2 deletions
@@ -1,4 +1,5 @@
using Jiaowu.Api.Domain.Academic;
using Jiaowu.Api.Infrastructure.Caching;
using Jiaowu.Api.Infrastructure.Persistence;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
@@ -18,6 +19,7 @@ public sealed class DemoDataSeederTests
var seeder = new DemoDataSeeder(
db,
NoOpAppCache.Instance,
NullLogger<DemoDataSeeder>.Instance);
await seeder.SeedAsync();
@@ -46,6 +48,7 @@ public sealed class DemoDataSeederTests
var seeder = new DemoDataSeeder(
db,
NoOpAppCache.Instance,
NullLogger<DemoDataSeeder>.Instance);
var exception = await Assert.ThrowsAsync<InvalidOperationException>(
@@ -70,6 +73,7 @@ public sealed class DemoDataSeederTests
var seeder = new DemoDataSeeder(
db,
NoOpAppCache.Instance,
NullLogger<DemoDataSeeder>.Instance);
await Assert.ThrowsAsync<KeyNotFoundException>(() => seeder.SeedAsync());
@@ -52,6 +52,14 @@ public sealed class StatisticsControllerTests
null,
CancellationToken.None);
Assert.Equal(1, TotalCourses(first));
Assert.Equal(
new[]
{
AppCacheTags.Analytics,
AppCacheTags.BaseData,
AppCacheTags.Timetables
},
cache.Tags.Single());
db.Courses.Add(CreateCourse("C003", firstCollege, category));
await db.SaveChangesAsync();
@@ -115,6 +123,7 @@ public sealed class StatisticsControllerTests
public int SourceCalls { get; private set; }
public IReadOnlyCollection<string> Keys => values.Keys;
public List<IReadOnlyCollection<string>> Tags { get; } = [];
public async Task<T> GetOrCreateAsync<T>(
string key,
@@ -127,6 +136,7 @@ public sealed class StatisticsControllerTests
return (T)value;
SourceCalls++;
Tags.Add(tags.ToArray());
var loaded = await factory(cancellationToken);
values[key] = loaded!;
return loaded;