mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2025-08-11 15:29:01 +08:00
perf (core): DomainResolveProcessor now cache results
This commit is contained in:
parent
8f5d027080
commit
77604a3544
6
backend/dist/cron-sync-artifacts.min.js
vendored
6
backend/dist/cron-sync-artifacts.min.js
vendored
File diff suppressed because one or more lines are too long
6
backend/dist/sub-store-parser.loon.min.js
vendored
6
backend/dist/sub-store-parser.loon.min.js
vendored
File diff suppressed because one or more lines are too long
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "sub-store",
|
"name": "sub-store",
|
||||||
"version": "2.11.5",
|
"version": "2.12.0",
|
||||||
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
|
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
|
||||||
"main": "src/main.js",
|
"main": "src/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
|
import resourceCache from '@/utils/resource-cache';
|
||||||
import { isIPv4, isIPv6 } from '@/utils';
|
import { isIPv4, isIPv6 } from '@/utils';
|
||||||
import { FULL } from '@/utils/logical';
|
import { FULL } from '@/utils/logical';
|
||||||
import { getFlag } from '@/utils/geo';
|
import { getFlag } from '@/utils/geo';
|
||||||
import lodash from 'lodash';
|
import lodash from 'lodash';
|
||||||
import $ from '@/core/app';
|
import $ from '@/core/app';
|
||||||
|
import { hex_md5 } from '@/vendor/md5';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The rule "(name CONTAINS "🇨🇳") AND (port IN [80, 443])" can be expressed as follows:
|
The rule "(name CONTAINS "🇨🇳") AND (port IN [80, 443])" can be expressed as follows:
|
||||||
{
|
{
|
||||||
operator: "AND",
|
operator: "AND",
|
||||||
child: [
|
child: [
|
||||||
{
|
{
|
||||||
@ -21,7 +23,7 @@ The rule "(name CONTAINS "🇨🇳") AND (port IN [80, 443])" can be expressed a
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function ConditionalFilter({ rule }) {
|
function ConditionalFilter({ rule }) {
|
||||||
return {
|
return {
|
||||||
@ -310,6 +312,9 @@ function ScriptOperator(script, targetPlatform, $arguments) {
|
|||||||
|
|
||||||
const DOMAIN_RESOLVERS = {
|
const DOMAIN_RESOLVERS = {
|
||||||
Google: async function (domain) {
|
Google: async function (domain) {
|
||||||
|
const id = hex_md5(`GOOGLE:${domain}`);
|
||||||
|
const cached = resourceCache.get(id);
|
||||||
|
if (cached) return cached;
|
||||||
const resp = await $.http.get({
|
const resp = await $.http.get({
|
||||||
url: `https://8.8.4.4/resolve?name=${encodeURIComponent(
|
url: `https://8.8.4.4/resolve?name=${encodeURIComponent(
|
||||||
domain,
|
domain,
|
||||||
@ -326,9 +331,14 @@ const DOMAIN_RESOLVERS = {
|
|||||||
if (answers.length === 0) {
|
if (answers.length === 0) {
|
||||||
throw new Error('No answers');
|
throw new Error('No answers');
|
||||||
}
|
}
|
||||||
return answers[answers.length - 1].data;
|
const result = answers[answers.length - 1].data;
|
||||||
|
resourceCache.set(id, result);
|
||||||
|
return result;
|
||||||
},
|
},
|
||||||
'IP-API': async function (domain) {
|
'IP-API': async function (domain) {
|
||||||
|
const id = hex_md5(`IP-API:${domain}`);
|
||||||
|
const cached = resourceCache.get(id);
|
||||||
|
if (cached) return cached;
|
||||||
const resp = await $.http.get({
|
const resp = await $.http.get({
|
||||||
url: `http://ip-api.com/json/${encodeURIComponent(
|
url: `http://ip-api.com/json/${encodeURIComponent(
|
||||||
domain,
|
domain,
|
||||||
@ -338,9 +348,14 @@ const DOMAIN_RESOLVERS = {
|
|||||||
if (body['status'] !== 'success') {
|
if (body['status'] !== 'success') {
|
||||||
throw new Error(`Status is ${body['status']}`);
|
throw new Error(`Status is ${body['status']}`);
|
||||||
}
|
}
|
||||||
return body.query;
|
const result = body.query;
|
||||||
|
resourceCache.set(id, result);
|
||||||
|
return result;
|
||||||
},
|
},
|
||||||
Cloudflare: async function (domain) {
|
Cloudflare: async function (domain) {
|
||||||
|
const id = hex_md5(`CLOUDFLARE:${domain}`);
|
||||||
|
const cached = resourceCache.get(id);
|
||||||
|
if (cached) return cached;
|
||||||
const resp = await $.http.get({
|
const resp = await $.http.get({
|
||||||
url: `https://1.0.0.1/dns-query?name=${encodeURIComponent(
|
url: `https://1.0.0.1/dns-query?name=${encodeURIComponent(
|
||||||
domain,
|
domain,
|
||||||
@ -357,7 +372,9 @@ const DOMAIN_RESOLVERS = {
|
|||||||
if (answers.length === 0) {
|
if (answers.length === 0) {
|
||||||
throw new Error('No answers');
|
throw new Error('No answers');
|
||||||
}
|
}
|
||||||
return answers[answers.length - 1].data;
|
const result = answers[answers.length - 1].data;
|
||||||
|
resourceCache.set(id, result);
|
||||||
|
return result;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
6
backend/sub-store.min.js
vendored
6
backend/sub-store.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user