fix(fr007-cache): 直查命中失效快照+去冗余排序+重载失败保旧快照防重试风暴

- EodPriceQueryService.TryGetPrice: FR007 快照 miss 直查库命中后 Invalidate,
  下次访问整表重载回 O(1),否则该键 TTL 窗口内每次读取都退化为点查
- 移除点查多余的 OrderByDescending(主键等值查询取首行即可)
- Fr007FixingCache.EnsureFresh: 重载失败(DB抖动)保留旧快照不抛并重置TTL时钟
  ——历史定盘不可变旧值依旧正确,同时防重试风暴;版本失效路径不受TTL掩盖
- 补两测试: 重载失败保快照窗口内不重试 / 首次装载失败miss不抛窗口内不重试
This commit is contained in:
hjhan
2026-08-18 09:33:28 +08:00
parent e219bdae18
commit 7a5089555d
3 changed files with 56 additions and 6 deletions
@@ -156,7 +156,7 @@ namespace YLErp.Modules.DataProviderModule
return true;
using var db = DbContextFactory.GetYLDbContext();
var data = db.eod_commodity_future_price.Where(x => x.ValueDate == valueDate && x.UnderlyingCode == underlyingCode).OrderByDescending(o => o.ValueDate).FirstOrDefault();
var data = db.eod_commodity_future_price.Where(x => x.ValueDate == valueDate && x.UnderlyingCode == underlyingCode).FirstOrDefault();
if (data != null)
{
@@ -164,6 +164,11 @@ namespace YLErp.Modules.DataProviderModule
// 利息腿计算直接作为 floatRate 参与 principal*(fixedRate+floatRate)/annualDays,无需再 ÷100。
price = data.ReferencePrice ?? 0;
// 快照漏掉的行(当日新发布/补录历史)直查命中——失效快照,下次访问整表重载后回到 O(1),
// 否则该键在 TTL 窗口内每次读取都退化为点查。
if (underlyingCode == Fr007FixingCache.UnderlyingCode)
Fr007FixingCache.Invalidate();
return true;
}