Improve performance of link preview parsing
This commit is contained in:
parent
1a4bc49563
commit
517007ad04
1 changed files with 1 additions and 4 deletions
|
@ -290,8 +290,6 @@ const getHtmlDocument = async (
|
||||||
abortSignal: AbortSignal,
|
abortSignal: AbortSignal,
|
||||||
logger: Pick<LoggerType, 'warn'> = log
|
logger: Pick<LoggerType, 'warn'> = log
|
||||||
): Promise<HTMLDocument> => {
|
): Promise<HTMLDocument> => {
|
||||||
let result: HTMLDocument = emptyHtmlDocument();
|
|
||||||
|
|
||||||
const buffer = new Uint8Array(MAX_HTML_BYTES_TO_LOAD);
|
const buffer = new Uint8Array(MAX_HTML_BYTES_TO_LOAD);
|
||||||
let bytesLoadedSoFar = 0;
|
let bytesLoadedSoFar = 0;
|
||||||
|
|
||||||
|
@ -313,8 +311,6 @@ const getHtmlDocument = async (
|
||||||
buffer.set(truncatedChunk, bytesLoadedSoFar);
|
buffer.set(truncatedChunk, bytesLoadedSoFar);
|
||||||
bytesLoadedSoFar += truncatedChunk.byteLength;
|
bytesLoadedSoFar += truncatedChunk.byteLength;
|
||||||
|
|
||||||
result = parseHtmlBytes(buffer.slice(0, bytesLoadedSoFar), httpCharset);
|
|
||||||
|
|
||||||
const hasLoadedMaxBytes = bytesLoadedSoFar >= buffer.length;
|
const hasLoadedMaxBytes = bytesLoadedSoFar >= buffer.length;
|
||||||
if (hasLoadedMaxBytes) {
|
if (hasLoadedMaxBytes) {
|
||||||
break;
|
break;
|
||||||
|
@ -326,6 +322,7 @@ const getHtmlDocument = async (
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const result = parseHtmlBytes(buffer.slice(0, bytesLoadedSoFar), httpCharset);
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue