perf(代码审查落地): 后端 A1-A8 与前端 C1-C8 加固,retention 清理补索引(V141)
A 组(backend-java): - A1 载荷引用计数不再无条件回落全表 COUNT - A2 结果行读取由 LIMIT 1 改整页 - A3 ziniao 索引缓存过期判断下推 SQL - A4 循环子任务认领改 CAS,失败一律抛 - A5 建单事务里不碰外部 IO - A6 连接池补网络层超时(connectTimeout/socketTimeout,env 可覆盖) - A7 日志留现场 + 异步落盘 - A8 其余:货源图片预取、结果工作簿装配等 - V141:三条 retention DELETE 的可用索引,其中 biz_price_track_loop_run 用 STORED 生成列承载 COALESCE 时间线(该表实测 881 行/17MB,COPY 秒级) C 组(frontend-vue):URL 取值走 safe-url、行号取值走 row-id、 交付视频任务状态抽成 delivery-video-task-state.ts,各补用例。
This commit is contained in:
+14
-6
@@ -76,16 +76,21 @@ public class ZiniaoMemoryStoreService {
|
||||
public <T> List<T> listByType(String cacheType, Class<T> valueType, int limit) {
|
||||
String normalizedType = normalizeRequired(cacheType, "cacheType 不能为空");
|
||||
int safeLimit = Math.max(limit, 1);
|
||||
// 过期判断必须在 SQL 里做:原来先按 cache_key 取 LIMIT N 再在 Java 里滤掉过期行,
|
||||
// 于是过期行会白占 N 这个窗口——同一 cache_type 存量超过 N 时,排在窗口之后的
|
||||
// 有效行根本取不到,调用方(店铺名索引兜底扫描)把「其实存在」判成未命中。
|
||||
// 同时过期行不再把 payload_json 整列拖回应用侧反序列化。
|
||||
// 走 uk_type_key(cache_type, cache_key):等值 + 排序都命中索引,expires_at 作回表过滤。
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
List<ZiniaoMemoryStoreEntity> entities = ziniaoMemoryStoreMapper.selectList(new LambdaQueryWrapper<ZiniaoMemoryStoreEntity>()
|
||||
.eq(ZiniaoMemoryStoreEntity::getCacheType, normalizedType)
|
||||
.gt(ZiniaoMemoryStoreEntity::getExpiresAt, now)
|
||||
.orderByAsc(ZiniaoMemoryStoreEntity::getCacheKey)
|
||||
.last("LIMIT " + safeLimit));
|
||||
if (entities.isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
return entities.stream()
|
||||
.filter(entity -> entity.getExpiresAt() != null && entity.getExpiresAt().isAfter(now))
|
||||
.map(entity -> deserialize(entity.getPayloadJson(), valueType))
|
||||
.filter(Objects::nonNull)
|
||||
.toList();
|
||||
@@ -133,8 +138,11 @@ public class ZiniaoMemoryStoreService {
|
||||
entity.setCreatedAt(now);
|
||||
entity.setUpdatedAt(now);
|
||||
ziniaoMemoryStoreMapper.insert(entity);
|
||||
// 店铺索引条目按「每店两把键(shopId + 名称别名)× 每轮刷新」成批写入,
|
||||
// 逐行 INFO 等于把刷新规模原样刷进日志文件;汇总行数已在
|
||||
// ZiniaoShopIndexService 的 `[ziniao-index] refresh persist` 里给出,这里降到 DEBUG。
|
||||
if (CACHE_TYPE_SHOP_INDEX_ENTRY.equals(normalizedType)) {
|
||||
log.info("[ziniao-shop-index-db] insert cacheKey={} companyNameSample={} expiresAt={} bytes={}",
|
||||
log.debug("[ziniao-shop-index-db] insert cacheKey={} companyNameSample={} expiresAt={} bytes={}",
|
||||
normalizedKey, sampleCompanyNameForLog(companyName), expiresAt, payloadJson.length());
|
||||
}
|
||||
return;
|
||||
@@ -146,7 +154,7 @@ public class ZiniaoMemoryStoreService {
|
||||
entity.setUpdatedAt(now);
|
||||
ziniaoMemoryStoreMapper.updateById(entity);
|
||||
if (CACHE_TYPE_SHOP_INDEX_ENTRY.equals(normalizedType)) {
|
||||
log.info("[ziniao-shop-index-db] update cacheKey={} id={} companyNameSample={} expiresAt={} bytes={}",
|
||||
log.debug("[ziniao-shop-index-db] update cacheKey={} id={} companyNameSample={} expiresAt={} bytes={}",
|
||||
normalizedKey, entity.getId(), sampleCompanyNameForLog(companyName), expiresAt, payloadJson.length());
|
||||
}
|
||||
}
|
||||
@@ -159,7 +167,7 @@ public class ZiniaoMemoryStoreService {
|
||||
if (entity != null) {
|
||||
ziniaoMemoryStoreMapper.deleteById(entity.getId());
|
||||
if (CACHE_TYPE_SHOP_INDEX_ENTRY.equals(normalizedType)) {
|
||||
log.info("[ziniao-shop-index-db] delete cacheKey={} id={} companyNameSample={}",
|
||||
log.debug("[ziniao-shop-index-db] delete cacheKey={} id={} companyNameSample={}",
|
||||
entity.getCacheKey(), entity.getId(), sampleCompanyNameForLog(entity.getCompanyName()));
|
||||
}
|
||||
}
|
||||
@@ -200,7 +208,7 @@ public class ZiniaoMemoryStoreService {
|
||||
}
|
||||
updated += ziniaoMemoryStoreMapper.updateById(row);
|
||||
if (CACHE_TYPE_SHOP_INDEX_ENTRY.equals(row.getCacheType())) {
|
||||
log.info("[ziniao-shop-index-db] mark-stale cacheKey={} id={} companyNameSample={} expiresAt={} bytes={}",
|
||||
log.debug("[ziniao-shop-index-db] mark-stale cacheKey={} id={} companyNameSample={} expiresAt={} bytes={}",
|
||||
row.getCacheKey(), row.getId(), sampleCompanyNameForLog(row.getCompanyName()),
|
||||
row.getExpiresAt(), row.getPayloadJson() == null ? 0 : row.getPayloadJson().length());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user