fix(search): return fallback summaries sooner
This commit is contained in:
1 parent
0bd47ad1fb
commit
02241eb0fa
1 file changed
+54
-33
+54
-33
@@ -498,29 +498,56 @@ export class SearcherHost extends RPCHost {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let earlyReturn = false;
|
let earlyReturn = false;
|
||||||
|
const returnTextResults = async (scrapped?: FormattedPage[]) => {
|
||||||
|
const fallbackResults = scrapped || trimmedResults;
|
||||||
|
await assigningOfGeneralMixins;
|
||||||
|
chargeAmount = this.assignChargeAmount(
|
||||||
|
fallbackResults,
|
||||||
|
count,
|
||||||
|
chargeAmountScaler,
|
||||||
|
fallbackQuery,
|
||||||
|
);
|
||||||
|
|
||||||
|
return assignTransferProtocolMeta(`${fallbackResults}`, {
|
||||||
|
contentType: "text/plain",
|
||||||
|
envelope: null,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
const returnJsonResults = async (scrapped?: FormattedPage[]) => {
|
||||||
|
const fallbackResults = scrapped || trimmedResults;
|
||||||
|
await assigningOfGeneralMixins;
|
||||||
|
chargeAmount = this.assignChargeAmount(
|
||||||
|
fallbackResults,
|
||||||
|
count,
|
||||||
|
chargeAmountScaler,
|
||||||
|
fallbackQuery,
|
||||||
|
);
|
||||||
|
|
||||||
|
return fallbackResults;
|
||||||
|
};
|
||||||
if (
|
if (
|
||||||
!ctx.accepts("text/plain") &&
|
!ctx.accepts("text/plain") &&
|
||||||
(ctx.accepts("text/json") || ctx.accepts("application/json"))
|
(ctx.accepts("text/json") || ctx.accepts("application/json"))
|
||||||
) {
|
) {
|
||||||
let earlyReturnTimer: ReturnType<typeof setTimeout> | undefined;
|
let earlyReturnTimer: ReturnType<typeof setTimeout> | undefined;
|
||||||
|
const hardReturnTimer = setTimeout(
|
||||||
|
async () => {
|
||||||
|
if (earlyReturn || rpcReflect.signal.aborted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
rpcReflect.return(await returnJsonResults(lastScrapped));
|
||||||
|
earlyReturn = true;
|
||||||
|
},
|
||||||
|
(crawlerOptions.timeout || 0) * 1000 || this.reasonableDelayMs,
|
||||||
|
);
|
||||||
const setEarlyReturnTimer = () => {
|
const setEarlyReturnTimer = () => {
|
||||||
if (earlyReturnTimer) {
|
if (earlyReturnTimer) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
earlyReturnTimer = setTimeout(
|
earlyReturnTimer = setTimeout(
|
||||||
async () => {
|
async () => {
|
||||||
if (!lastScrapped) {
|
rpcReflect.return(await returnJsonResults(lastScrapped));
|
||||||
return;
|
|
||||||
}
|
|
||||||
await assigningOfGeneralMixins;
|
|
||||||
chargeAmount = this.assignChargeAmount(
|
|
||||||
lastScrapped,
|
|
||||||
count,
|
|
||||||
chargeAmountScaler,
|
|
||||||
fallbackQuery,
|
|
||||||
);
|
|
||||||
|
|
||||||
rpcReflect.return(lastScrapped);
|
|
||||||
earlyReturn = true;
|
earlyReturn = true;
|
||||||
},
|
},
|
||||||
(crawlerOptions.timeout || 0) * 1000 || this.reasonableDelayMs,
|
(crawlerOptions.timeout || 0) * 1000 || this.reasonableDelayMs,
|
||||||
@@ -555,6 +582,7 @@ export class SearcherHost extends RPCHost {
|
|||||||
if (earlyReturnTimer) {
|
if (earlyReturnTimer) {
|
||||||
clearTimeout(earlyReturnTimer);
|
clearTimeout(earlyReturnTimer);
|
||||||
}
|
}
|
||||||
|
clearTimeout(hardReturnTimer);
|
||||||
|
|
||||||
if (!lastScrapped) {
|
if (!lastScrapped) {
|
||||||
throw new AssertionFailureError(
|
throw new AssertionFailureError(
|
||||||
@@ -576,29 +604,24 @@ export class SearcherHost extends RPCHost {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let earlyReturnTimer: ReturnType<typeof setTimeout> | undefined;
|
let earlyReturnTimer: ReturnType<typeof setTimeout> | undefined;
|
||||||
|
const hardReturnTimer = setTimeout(
|
||||||
|
async () => {
|
||||||
|
if (earlyReturn || rpcReflect.signal.aborted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
rpcReflect.return(await returnTextResults(lastScrapped));
|
||||||
|
earlyReturn = true;
|
||||||
|
},
|
||||||
|
(crawlerOptions.timeout || 0) * 1000 || this.reasonableDelayMs,
|
||||||
|
);
|
||||||
const setEarlyReturnTimer = () => {
|
const setEarlyReturnTimer = () => {
|
||||||
if (earlyReturnTimer) {
|
if (earlyReturnTimer) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
earlyReturnTimer = setTimeout(
|
earlyReturnTimer = setTimeout(
|
||||||
async () => {
|
async () => {
|
||||||
if (!lastScrapped) {
|
rpcReflect.return(await returnTextResults(lastScrapped));
|
||||||
return;
|
|
||||||
}
|
|
||||||
await assigningOfGeneralMixins;
|
|
||||||
chargeAmount = this.assignChargeAmount(
|
|
||||||
lastScrapped,
|
|
||||||
count,
|
|
||||||
chargeAmountScaler,
|
|
||||||
fallbackQuery,
|
|
||||||
);
|
|
||||||
|
|
||||||
rpcReflect.return(
|
|
||||||
assignTransferProtocolMeta(`${lastScrapped}`, {
|
|
||||||
contentType: "text/plain",
|
|
||||||
envelope: null,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
earlyReturn = true;
|
earlyReturn = true;
|
||||||
},
|
},
|
||||||
(crawlerOptions.timeout || 0) * 1000 || this.reasonableDelayMs,
|
(crawlerOptions.timeout || 0) * 1000 || this.reasonableDelayMs,
|
||||||
@@ -638,6 +661,7 @@ export class SearcherHost extends RPCHost {
|
|||||||
if (earlyReturnTimer) {
|
if (earlyReturnTimer) {
|
||||||
clearTimeout(earlyReturnTimer);
|
clearTimeout(earlyReturnTimer);
|
||||||
}
|
}
|
||||||
|
clearTimeout(hardReturnTimer);
|
||||||
|
|
||||||
if (!lastScrapped) {
|
if (!lastScrapped) {
|
||||||
throw new AssertionFailureError(
|
throw new AssertionFailureError(
|
||||||
@@ -655,10 +679,7 @@ export class SearcherHost extends RPCHost {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return assignTransferProtocolMeta(`${lastScrapped}`, {
|
return returnTextResults(lastScrapped);
|
||||||
contentType: "text/plain",
|
|
||||||
envelope: null,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in new issue
Block a user