From c85f9fac0ccc4dc9728050911012c0a6d76521ba Mon Sep 17 00:00:00 2001 From: SukkaW Date: Sun, 31 Dec 2023 03:01:43 +0800 Subject: [PATCH] Perf: enforce more cache --- Build/build-apple-cdn.ts | 11 ++++++++++- Build/lib/cache-filesystem.ts | 2 +- Build/lib/reject-data-source.ts | 11 ++++++----- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Build/build-apple-cdn.ts b/Build/build-apple-cdn.ts index ac6594e7..76d05755 100644 --- a/Build/build-apple-cdn.ts +++ b/Build/build-apple-cdn.ts @@ -6,10 +6,19 @@ import { task, traceAsync } from './lib/trace-runner'; import { SHARED_DESCRIPTION } from './lib/constants'; import picocolors from 'picocolors'; import { createMemoizedPromise } from './lib/memo-promise'; +import { TTL, deserializeArray, fsCache, serializeArray } from './lib/cache-filesystem'; export const getAppleCdnDomainsPromise = createMemoizedPromise(() => traceAsync( picocolors.gray('download dnsmasq-china-list apple.china.conf'), - () => parseFelixDnsmasq('https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/apple.china.conf'), + () => fsCache.apply( + 'https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/apple.china.conf', + () => parseFelixDnsmasq('https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/apple.china.conf'), + { + ttl: TTL.THREE_DAYS(), + serializer: serializeArray, + deserializer: deserializeArray + } + ), picocolors.gray )); diff --git a/Build/lib/cache-filesystem.ts b/Build/lib/cache-filesystem.ts index 935452cb..d886cc5e 100644 --- a/Build/lib/cache-filesystem.ts +++ b/Build/lib/cache-filesystem.ts @@ -143,7 +143,7 @@ export const TTL = { TEN_DAYS: () => randomInt(9, 11) * 24 * 60 * 60 * 1000 }; -const separator = String.fromCharCode(0); +const separator = '\u0000'; // const textEncoder = new TextEncoder(); // const textDecoder = new TextDecoder(); // export const serializeString = (str: string) => textEncoder.encode(str); diff --git a/Build/lib/reject-data-source.ts b/Build/lib/reject-data-source.ts index cbd44413..87f27849 100644 --- a/Build/lib/reject-data-source.ts +++ b/Build/lib/reject-data-source.ts @@ -7,8 +7,8 @@ export const HOSTS = [ ['https://raw.githubusercontent.com/hoshsadiq/adblock-nocoin-list/master/hosts.txt', false, false, TTL.THREE_DAYS()], // have not been updated for more than a year, so we set a 14 days cache ttl ['https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy.txt', true, false, TTL.TWO_WEEKS()], - ['https://raw.githubusercontent.com/jerryn70/GoodbyeAds/master/Extension/GoodbyeAds-Xiaomi-Extension.txt', false], - ['https://raw.githubusercontent.com/jerryn70/GoodbyeAds/master/Extension/GoodbyeAds-Huawei-Extension.txt', false], + ['https://raw.githubusercontent.com/jerryn70/GoodbyeAds/master/Extension/GoodbyeAds-Xiaomi-Extension.txt', false, false, TTL.THREE_DAYS()], + ['https://raw.githubusercontent.com/jerryn70/GoodbyeAds/master/Extension/GoodbyeAds-Huawei-AdBlock.txt', false, false, TTL.THREE_DAYS()], // ad-wars is not actively maintained, so we set a 7 days cache ttl ['https://raw.githubusercontent.com/jdlingyu/ad-wars/master/hosts', false, false, TTL.ONE_WEEK()], ['https://raw.githubusercontent.com/durablenapkin/block/master/luminati.txt', true], @@ -58,7 +58,7 @@ export const ADGUARD_FILTERS = [ 'https://ublockorigin.github.io/uAssetsCDN/thirdparties/easylist.txt', 'https://ublockorigin.pages.dev/thirdparties/easylist.txt' ], - 12 * 60 * 60 * 1000 + TTL.TWLVE_HOURS() ], // EasyPrivacy [ @@ -70,7 +70,7 @@ export const ADGUARD_FILTERS = [ 'https://ublockorigin.github.io/uAssetsCDN/thirdparties/easyprivacy.txt', 'https://ublockorigin.pages.dev/thirdparties/easyprivacy.txt' ], - 12 * 60 * 60 * 1000 + TTL.TWLVE_HOURS() ], // AdGuard DNS Filter [ @@ -78,7 +78,8 @@ export const ADGUARD_FILTERS = [ [ 'https://filters.adtidy.org/extension/ublock/filters/15_optimized.txt', 'https://adguardteam.github.io/HostlistsRegistry/assets/filter_1.txt' - ] + ], + TTL.TWLVE_HOURS() ], // uBlock Origin Filter List [