refactor(brand-check): 归属用户读取下沉为 SecretUsageContext.currentUserId()

上一笔在 AppearancePatentLlmClient 里就地取上下文(+6 行),把那支已进超长点名
台账的文件从 1465 顶到 1471,可读棘轮按对象判红。改为未入册的 SecretUsageContext
提供一个静态访问器(含「无上下文就不该打上游」的口径),调用点回到一行——该文件
现在 1464 行,比基线还短一行。AP/品牌相关 273 例全绿,test-compile 零错误。
This commit is contained in:
2026-10-20 20:54:47 +08:00
parent 3500feb921
commit e855801237
2 changed files with 7 additions and 7 deletions
@@ -1042,13 +1042,7 @@ public class AppearancePatentLlmClient {
BrandCheckClient.BrandCheckBatchResult[] byRowIndex =
new BrandCheckClient.BrandCheckBatchResult[results.size()];
if (!pending.isEmpty()) {
// 品牌检查用的代理=这批结果归属那个用户自己的提取链接(16890 不再兜底平台 key)。
// 取不到任务上下文就是无人归属,此时不去打上游:上游要么用别人的套餐、要么裸 IP 被拒,
// 两种都把一次配置缺失变成一笔算不清的账。
SecretUsageContext.Context usage = SecretUsageContext.current();
Long ownerUserId = usage == null ? null : usage.userId();
List<BrandCheckClient.BrandCheckBatchResult> batch =
brandCheckClient.checkTitleTexts(titles, "Terms", ownerUserId);
List<BrandCheckClient.BrandCheckBatchResult> batch = brandCheckClient.checkTitleTexts(titles, "Terms", SecretUsageContext.currentUserId());
for (int k = 0; k < pending.size(); k++) {
byRowIndex[pending.get(k)] = batch.get(k);
}
@@ -45,6 +45,12 @@ public final class SecretUsageContext {
return context != null && context.usable() ? context : null;
}
/** 当前归属用户 id;无任务上下文时为 null——调用方据此拒绝打上游,别拿别人的套餐。 */
public static Long currentUserId() {
Context context = current();
return context == null ? null : context.userId();
}
/** 捕获当前上下文快照,供工作线程恢复;无上下文时返回 null。 */
public static Context snapshot() {
return HOLDER.get();