Skip to content

Commit c478b98

Browse files
committed
feat: 增加后端请求并发配置(后端 >= 2.23.32)
1 parent 1179f89 commit c478b98

8 files changed

Lines changed: 85 additions & 6 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sub-store-front-end",
3-
"version": "2.17.24",
3+
"version": "2.17.27",
44
"private": true,
55
"scripts": {
66
"dev": "vite --host",

src/api/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ const getResponseContent = (e: AxiosError<ErrorResponse>) => {
7878
return [statusLine, getText(e.message)].filter(Boolean).join('\n') || undefined;
7979
};
8080

81+
const isCanceledRequestError = (error: AxiosError<ErrorResponse>) => {
82+
return error.name === 'AbortError'
83+
|| error.name === 'CanceledError'
84+
|| error.code === 'ERR_CANCELED'
85+
|| error.message === 'canceled'
86+
|| axios.isCancel(error);
87+
};
88+
8189
// 配置新建一个 axios 实例
8290
const service = axios.create({
8391
baseURL: getHostAPIUrl(),
@@ -94,6 +102,9 @@ service.interceptors.response.use(
94102
// console.log(e.config.url);
95103
const requestUrl = e.config?.url || '';
96104

105+
if (isCanceledRequestError(e))
106+
return Promise.reject(e);
107+
97108
// 流量信息接口的报错,不通知,直接返回
98109
if (requestUrl.startsWith('/api/sub/flow') || requestUrl.startsWith('https://api.github.com/'))
99110
return Promise.resolve(e.response);

src/locales/en.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ export default {
532532
],
533533
cache: ["Enabled", "Disabled"],
534534
concurrency: "Request Concurrency",
535-
concurrencyPlaceholder: "Default 15. Keep proxy apps at 20 or less",
535+
concurrencyPlaceholder: "Default 10. Keep proxy apps at 20 or less",
536536
tipsTitle: "domain Tips",
537537
tipsDes: "Operation instructions for node domain name resolution",
538538
},
@@ -730,6 +730,8 @@ export default {
730730
defaultFlowUserAgent: "Please input Default Flow User-Agent",
731731
defaultProxy: "Please input Default Proxy/Policy",
732732
defaultTimeout: "Default Timeout (in ms, default: 8000)",
733+
backendRequestConcurrency: "Backend Request Concurrency (default: 10)",
734+
backendRequestConcurrencyWaitTime: "Backend Request Concurrency Wait Time (in ms, default: 0)",
733735
cacheThreshold: "Cache Threshold (in KB, default: 1024)",
734736
resourceCacheTtl: 'Resource Cache TTL, default: 3600(s)',
735737
headersCacheTtl: 'Headers Cache TTL, default: 60(s)',

src/locales/ru.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ export default {
518518
"Отключено"
519519
],
520520
"concurrency": "Конкурентность запросов",
521-
"concurrencyPlaceholder": "По умолчанию 15. Рекомендуется ставить не более 20",
521+
"concurrencyPlaceholder": "По умолчанию 10. Рекомендуется ставить не более 20",
522522
"tipsTitle": "Подсказки по резолву",
523523
"tipsDes": "Инструкции по разрешению доменных имен узлов в IP-адреса"
524524
},
@@ -779,6 +779,8 @@ export default {
779779
"defaultFlowUserAgent": "Введите User-Agent для трафика по умолчанию",
780780
"defaultProxy": "Укажите дефолтный прокси/политику бэкенда",
781781
"defaultTimeout": "Таймаут по умолчанию (в мс, по умолчанию: 8000)",
782+
"backendRequestConcurrency": "Параллельные запросы бэкенда (по умолчанию: 10)",
783+
"backendRequestConcurrencyWaitTime": "Ожидание параллельных запросов бэкенда (в мс, по умолчанию: 0)",
782784
"cacheThreshold": "Порог кэширования (в КБ, по умолчанию: 1024)",
783785
"resourceCacheTtl": "TTL кэша ресурсов, по умолчанию: 3600 (сек)",
784786
"headersCacheTtl": "TTL кэша заголовков, по умолчанию: 60 (сек)",

src/locales/zh.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ export default {
549549
filters: ['不过滤', '移除失败', '只保留 IP', '只保留 IPv4', '只保留 IPv6'],
550550
cache: ['启用', '禁用'],
551551
concurrency: '请求并发数',
552-
concurrencyPlaceholder: '默认 15. 在代理 App 中建议不超过 20',
552+
concurrencyPlaceholder: '默认 10. 在代理 App 中建议不超过 20',
553553
tipsTitle: '域名解析操作提示',
554554
tipsDes: '将节点域名解析成为 IP 地址,减少一次额外的 DNS 请求',
555555
},
@@ -694,6 +694,8 @@ export default {
694694
defaultFlowUserAgent: '请输入默认查询订阅流量信息 的 User-Agent',
695695
defaultProxy: '请输入默认代理/策略',
696696
defaultTimeout: '默认超时(单位: 毫秒, 默认: 8000)',
697+
backendRequestConcurrency: '后端请求并发数(默认: 10)',
698+
backendRequestConcurrencyWaitTime: '后端请求并发等待时间(单位: 毫秒, 默认: 0)',
697699
cacheThreshold: '缓存阈值(单位: KB, 默认: 1024)',
698700
resourceCacheTtl: '资源缓存(单位: 秒, 默认: 3600)',
699701
headersCacheTtl: '响应头缓存(单位: 秒, 默认: 60)',

src/store/settings.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ export const useSettingsStore = defineStore("settingsStore", {
106106
defaultFlowUserAgent: "",
107107
defaultProxy: "",
108108
defaultTimeout: "",
109+
backendRequestConcurrency: "",
110+
backendRequestConcurrencyWaitTime: "",
109111
cacheThreshold: "",
110112
resourceCacheTtl: "",
111113
headersCacheTtl: "",
@@ -212,6 +214,8 @@ export const useSettingsStore = defineStore("settingsStore", {
212214
this.defaultUserAgent = res.data.data.defaultUserAgent || "";
213215
this.defaultFlowUserAgent = res.data.data.defaultFlowUserAgent || "";
214216
this.defaultTimeout = res.data.data.defaultTimeout || "";
217+
this.backendRequestConcurrency = normalizeSettingInputValue(res.data.data.backendRequestConcurrency);
218+
this.backendRequestConcurrencyWaitTime = normalizeSettingInputValue(res.data.data.backendRequestConcurrencyWaitTime);
215219
this.cacheThreshold = res.data.data.cacheThreshold || "";
216220
this.resourceCacheTtl = res.data.data.resourceCacheTtl || "";
217221
this.headersCacheTtl = res.data.data.headersCacheTtl || "";
@@ -255,6 +259,8 @@ export const useSettingsStore = defineStore("settingsStore", {
255259
this.defaultUserAgent = res.data.data.defaultUserAgent || "";
256260
this.defaultFlowUserAgent = res.data.data.defaultFlowUserAgent || "";
257261
this.defaultTimeout = res.data.data.defaultTimeout || "";
262+
this.backendRequestConcurrency = normalizeSettingInputValue(res.data.data.backendRequestConcurrency);
263+
this.backendRequestConcurrencyWaitTime = normalizeSettingInputValue(res.data.data.backendRequestConcurrencyWaitTime);
258264
this.cacheThreshold = res.data.data.cacheThreshold || "";
259265
this.resourceCacheTtl = res.data.data.resourceCacheTtl || "";
260266
this.headersCacheTtl = res.data.data.headersCacheTtl || "";

src/types/store/settings.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ interface SettingsPostData {
2828
defaultUserAgent?: string;
2929
defaultFlowUserAgent?: string;
3030
defaultTimeout?: string;
31+
backendRequestConcurrency?: string;
32+
backendRequestConcurrencyWaitTime?: string;
3133
cacheThreshold?: string;
3234
resourceCacheTtl?: string;
3335
headersCacheTtl?: string;

src/views/My.vue

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,28 @@
334334
right-icon="tips"
335335
@click-right-icon="githubApiTimeoutTips"
336336
/>
337+
<nut-input
338+
class="input"
339+
v-model="backendRequestConcurrencyInput"
340+
:disabled="!isRequestConfigEditing"
341+
:placeholder="$t(`myPage.placeholder.backendRequestConcurrency`)"
342+
type="number"
343+
input-align="left"
344+
:left-icon="iconConcurrency"
345+
right-icon="tips"
346+
@click-right-icon="backendRequestConcurrencyTips"
347+
/>
348+
<nut-input
349+
class="input"
350+
v-model="backendRequestConcurrencyWaitTimeInput"
351+
:disabled="!isRequestConfigEditing"
352+
:placeholder="$t(`myPage.placeholder.backendRequestConcurrencyWaitTime`)"
353+
type="number"
354+
input-align="left"
355+
:left-icon="iconTimeout"
356+
right-icon="tips"
357+
@click-right-icon="backendRequestConcurrencyWaitTimeTips"
358+
/>
337359
</div>
338360
</div>
339361
<div class="config-card">
@@ -629,7 +651,7 @@ const router = useRouter();
629651
const { showNotify } = useAppNotifyStore();
630652
const { currentUrl: host } = useHostAPI();
631653
const settingsStore = useSettingsStore();
632-
const { githubUser, gistToken, syncTime, defaultUserAgent, defaultFlowUserAgent, defaultProxy, defaultTimeout, cacheThreshold, resourceCacheTtl, headersCacheTtl, scriptCacheTtl, logsMaxCount, syncPlatform, githubProxy, githubApiUrl, githubApiTimeout, artifactSyncBatchSize, githubProxyRegex, gistUpload } =
654+
const { githubUser, gistToken, syncTime, defaultUserAgent, defaultFlowUserAgent, defaultProxy, defaultTimeout, backendRequestConcurrency, backendRequestConcurrencyWaitTime, cacheThreshold, resourceCacheTtl, headersCacheTtl, scriptCacheTtl, logsMaxCount, syncPlatform, githubProxy, githubApiUrl, githubApiTimeout, artifactSyncBatchSize, githubProxyRegex, gistUpload } =
633655
storeToRefs(settingsStore);
634656
635657
const DEFAULT_GITHUB_API_URL = "https://api.github.com";
@@ -748,6 +770,8 @@ const uaInput = ref("");
748770
const flowUaInput = ref("");
749771
const proxyInput = ref("");
750772
const timeoutInput = ref("");
773+
const backendRequestConcurrencyInput = ref("");
774+
const backendRequestConcurrencyWaitTimeInput = ref("");
751775
const cacheThresholdInput = ref("");
752776
const resourceCacheTtlInput = ref("");
753777
const headersCacheTtlInput = ref("");
@@ -783,6 +807,8 @@ const toggleEditMode = async (type) => {
783807
defaultFlowUserAgent: flowUaInput.value,
784808
defaultProxy: proxyInput.value,
785809
defaultTimeout: timeoutInput.value,
810+
backendRequestConcurrency: backendRequestConcurrencyInput.value,
811+
backendRequestConcurrencyWaitTime: backendRequestConcurrencyWaitTimeInput.value,
786812
cacheThreshold: cacheThresholdInput.value,
787813
resourceCacheTtl: resourceCacheTtlInput.value,
788814
headersCacheTtl: headersCacheTtlInput.value,
@@ -812,6 +838,8 @@ const toggleEditMode = async (type) => {
812838
flowUaInput.value = defaultFlowUserAgent.value || "";
813839
proxyInput.value = defaultProxy.value;
814840
timeoutInput.value = defaultTimeout.value;
841+
backendRequestConcurrencyInput.value = backendRequestConcurrency.value || "";
842+
backendRequestConcurrencyWaitTimeInput.value = backendRequestConcurrencyWaitTime.value || "";
815843
cacheThresholdInput.value = cacheThreshold.value;
816844
resourceCacheTtlInput.value = resourceCacheTtl.value;
817845
headersCacheTtlInput.value = headersCacheTtl.value;
@@ -972,6 +1000,8 @@ const setDisplayInfo = () => {
9721000
flowUaInput.value = defaultFlowUserAgent.value || "";
9731001
proxyInput.value = defaultProxy.value || "";
9741002
timeoutInput.value = defaultTimeout.value || "";
1003+
backendRequestConcurrencyInput.value = backendRequestConcurrency.value || "";
1004+
backendRequestConcurrencyWaitTimeInput.value = backendRequestConcurrencyWaitTime.value || "";
9751005
cacheThresholdInput.value = cacheThreshold.value || "";
9761006
resourceCacheTtlInput.value = resourceCacheTtl.value || "";
9771007
headersCacheTtlInput.value = headersCacheTtl.value || "";
@@ -1266,6 +1296,30 @@ const timeoutTips = () => {
12661296
lockScroll: false,
12671297
});
12681298
};
1299+
const backendRequestConcurrencyTips = () => {
1300+
Dialog({
1301+
title: '后端请求并发数',
1302+
content: '后端需 >= 2.23.32\n\n控制后端发起外部请求时的并发数。默认 10;在代理 App 中建议不超过 20,过高可能增加连接数和内存压力。\n\n实际会用于远程资源下载,例如远程订阅、文件、脚本、预览、同步/定时同步等经后端下载工具发起的请求;也会用于订阅流量信息请求,例如 Subscription-Userinfo 的 HEAD/GET 请求。\n\n域名解析除外,它有自己的请求并发数。\n\n后端日志会输出 [Backend Request Concurrency],包含 active、pending、limit、waitTime,方便调试。',
1303+
popClass: 'auto-dialog',
1304+
textAlign: 'left',
1305+
okText: 'OK',
1306+
noCancelBtn: true,
1307+
closeOnPopstate: true,
1308+
lockScroll: false,
1309+
});
1310+
};
1311+
const backendRequestConcurrencyWaitTimeTips = () => {
1312+
Dialog({
1313+
title: '后端请求并发等待时间',
1314+
content: '后端需 >= 2.23.32\n\n每个受后端请求并发数限制的请求拿到并发槽后,先等待指定毫秒数再发出。默认 0。\n\n可用于降低代理 App 中后端请求的瞬时连接压力;数值越大,总处理耗时也会越长。\n\n作用范围与后端请求并发数一致:远程资源下载和订阅流量信息请求。域名解析除外,它有自己的请求并发数。',
1315+
popClass: 'auto-dialog',
1316+
textAlign: 'left',
1317+
okText: 'OK',
1318+
noCancelBtn: true,
1319+
closeOnPopstate: true,
1320+
lockScroll: false,
1321+
});
1322+
};
12691323
const cacheThresholdTips = () => {
12701324
Dialog({
12711325
title: '可尝试设置为 1024',
@@ -1324,7 +1378,7 @@ const logsMaxCountTips = () => {
13241378
const concurrencyTips = () => {
13251379
Dialog({
13261380
title: '并发数',
1327-
content: 'Shadowrocket 并发可能会爆内存, 可设为 1',
1381+
content: 'Shadowrocket/Surge 等代理 App 中并发数太高可能会爆内存, 可自行调整',
13281382
popClass: 'auto-dialog',
13291383
okText: 'OK',
13301384
noCancelBtn: true,

0 commit comments

Comments
 (0)