fix(search): 站点搜索失败、超时、被拦截的结果不再写缓存
之前失败结果也缓存 30 秒,只在一轮全部站点失败时才撤销;某站一次失败后, 后续几次搜索都复用同一个失败。现在只缓存成功结果,失败 / 超时 / 跳过下次直接重试。 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Cxwgnn2pbzQ7rXv3rq7fei
This commit is contained in:
1 parent
4fa001750b
commit
6e71df2769
2 files changed
+19
-15
No files matched your search
@@ -289,13 +289,20 @@ describe.skipIf(!up)("全局搜索", () => {
|
||||
expect(rows.length).toBe(3);
|
||||
});
|
||||
|
||||
it("30s 内相同查询命中缓存,不再请求站点", async () => {
|
||||
it("30s 内相同查询:成功的站点命中缓存不再请求;超时的站点不缓存,每次重试", async () => {
|
||||
const before = [nexusSearches(), mteamSearches(), slowCalls];
|
||||
const r = await req("/search?q=%20dune%20&scope=releases");
|
||||
expect(r.body.data.releases).toMatchObject({ cached: true, total: 3, partial: true });
|
||||
// 超时的站点重新查了一次,所以整体不算缓存结果
|
||||
expect(r.body.data.releases).toMatchObject({ cached: false, total: 3, partial: true });
|
||||
expect([nexusSearches(), mteamSearches()]).toEqual(before.slice(0, 2));
|
||||
expect(slowCalls).toBe(before[2]! + 1);
|
||||
const page = await req("/search/releases?q=Dune");
|
||||
expect(page.body.data).toMatchObject({ cached: true, total: 3 });
|
||||
expect([nexusSearches(), mteamSearches(), slowCalls]).toEqual(before);
|
||||
expect(page.body.data).toMatchObject({ cached: false, total: 3, partial: true });
|
||||
expect([nexusSearches(), mteamSearches()]).toEqual(before.slice(0, 2));
|
||||
expect(slowCalls).toBe(before[2]! + 2);
|
||||
// 只查成功过的站点:全部命中缓存
|
||||
const okOnly = await req(`/search/releases?q=Dune&sites=${sites.nexus},${sites.mteam}`);
|
||||
expect(okOnly.body.data).toMatchObject({ cached: true, total: 3, partial: false });
|
||||
// refresh=true 跳过缓存
|
||||
const fresh = await req("/search/releases?q=Dune&refresh=true");
|
||||
expect(fresh.body.data.cached).toBe(false);
|
||||
@@ -387,7 +394,9 @@ describe.skipIf(!up)("全局搜索", () => {
|
||||
});
|
||||
|
||||
it("筛选 / 排序 / 游标 / 分面", async () => {
|
||||
const q = (s: string) => req(`/search/releases?q=Dune&${s}`).then((r) => r.body.data);
|
||||
// 只查成功的两站(超时站点不缓存,每次重试会拖慢用例)
|
||||
const ok = `sites=${sites.nexus},${sites.mteam}`;
|
||||
const q = (s: string) => req(`/search/releases?q=Dune&${ok}&${s}`).then((r) => r.body.data);
|
||||
let d = await q("resolution=2160p");
|
||||
expect(d.items.map((i: Loose) => i.siteReleaseId).sort()).toEqual(["812345", "990001"]);
|
||||
expect(d).toMatchObject({ total: 2, unfilteredTotal: 3 });
|
||||
@@ -399,7 +408,7 @@ describe.skipIf(!up)("全局搜索", () => {
|
||||
|
||||
d = await q("source=web-dl,REMUX&free=false");
|
||||
expect(d.items.map((i: Loose) => i.siteReleaseId).sort()).toEqual(["900001", "990001"]);
|
||||
d = await q(`sites=${sites.mteam}`);
|
||||
d = (await req(`/search/releases?q=Dune&sites=${sites.mteam}`)).body.data;
|
||||
expect(d.items.map((i: Loose) => i.siteReleaseId)).toEqual(["990001"]);
|
||||
d = await q(`minSize=${10 * 1024 ** 3}&maxSize=${50 * 1024 ** 3}`);
|
||||
expect(d.items.map((i: Loose) => i.siteReleaseId)).toEqual(["990001"]);
|
||||
@@ -420,8 +429,9 @@ describe.skipIf(!up)("全局搜索", () => {
|
||||
});
|
||||
|
||||
it("快速筛选 qf(SEARCH-3):分面计数、同维度 OR / 跨维度 AND、分页一致", async () => {
|
||||
const ok = `sites=${sites.nexus},${sites.mteam}`;
|
||||
const q = (qf: string, extra = "") =>
|
||||
req(`/search/releases?q=Dune&qf=${encodeURIComponent(qf)}${extra}`).then((r) => r.body.data);
|
||||
req(`/search/releases?q=Dune&${ok}&qf=${encodeURIComponent(qf)}${extra}`).then((r) => r.body.data);
|
||||
const counts = (opts: Loose[]) => Object.fromEntries(opts.map((o) => [o.value, o.count]));
|
||||
const ids = (d: Loose) => d.items.map((i: Loose) => i.siteReleaseId).sort();
|
||||
|
||||
|
||||
Reference in new issue
Block a user