mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 09:10:35 +08:00
Perf: add cache to user-agent list
This commit is contained in:
parent
998b6e4b24
commit
10e4b19f40
@ -16,8 +16,17 @@ import { TTL, deserializeArray, fsCache, serializeArray } from './lib/cache-file
|
|||||||
|
|
||||||
const s = new Sema(2);
|
const s = new Sema(2);
|
||||||
|
|
||||||
const latestTopUserAgentsPromise = fetchWithRetry('https://unpkg.com/top-user-agents@latest/src/desktop.json')
|
const latestTopUserAgentsPromise = fsCache.apply(
|
||||||
.then(res => res.json<string[]>()).then(userAgents => userAgents.filter(ua => ua.startsWith('Mozilla/5.0 ')));
|
'https://unpkg.com/top-user-agents@latest/src/desktop.json',
|
||||||
|
() => fetchWithRetry('https://unpkg.com/top-user-agents@latest/src/desktop.json')
|
||||||
|
.then(res => res.json<string[]>())
|
||||||
|
.then(userAgents => userAgents.filter(ua => ua.startsWith('Mozilla/5.0 '))),
|
||||||
|
{
|
||||||
|
serializer: serializeArray,
|
||||||
|
deserializer: deserializeArray,
|
||||||
|
ttl: TTL.ONE_DAY()
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const querySpeedtestApi = async (keyword: string): Promise<Array<string | null>> => {
|
const querySpeedtestApi = async (keyword: string): Promise<Array<string | null>> => {
|
||||||
const topUserAgents = await latestTopUserAgentsPromise;
|
const topUserAgents = await latestTopUserAgentsPromise;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user