mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Perf: run filter TransformStream before parsing
This commit is contained in:
@@ -4,6 +4,7 @@ import { waitWithAbort } from 'foxts/wait';
|
||||
import { nullthrow } from 'foxts/guard';
|
||||
import { TextLineStream } from 'foxts/text-line-stream';
|
||||
import { ProcessLineStream } from './process-line';
|
||||
import { AdGuardFilterIgnoreUnsupportedLinesStream } from './parse-filter/filters';
|
||||
|
||||
// eslint-disable-next-line sukka/unicorn/custom-error-definition -- typescript is better
|
||||
class CustomAbortError extends Error {
|
||||
@@ -13,7 +14,10 @@ class CustomAbortError extends Error {
|
||||
|
||||
const reusedCustomAbortError = new CustomAbortError();
|
||||
|
||||
export async function fetchAssets(url: string, fallbackUrls: null | undefined | string[] | readonly string[], processLine = false, allowEmpty = false) {
|
||||
export async function fetchAssets(
|
||||
url: string, fallbackUrls: null | undefined | string[] | readonly string[],
|
||||
processLine = false, allowEmpty = false, filterAdGuardUnsupportedLines = false
|
||||
) {
|
||||
const controller = new AbortController();
|
||||
|
||||
const createFetchFallbackPromise = async (url: string, index: number) => {
|
||||
@@ -36,6 +40,9 @@ export async function fetchAssets(url: string, fallbackUrls: null | undefined |
|
||||
if (processLine) {
|
||||
stream = stream.pipeThrough(new ProcessLineStream());
|
||||
}
|
||||
if (filterAdGuardUnsupportedLines) {
|
||||
stream = stream.pipeThrough(new AdGuardFilterIgnoreUnsupportedLinesStream());
|
||||
}
|
||||
const arr = await Array.fromAsync(stream);
|
||||
|
||||
if (arr.length < 1 && !allowEmpty) {
|
||||
|
||||
Reference in New Issue
Block a user