Skip to content

Commit 756ba99

Browse files
committed
fix: message
1 parent 313b86a commit 756ba99

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

src/pages/background/core/rules.ts

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,14 @@ TABLE_NAMES_ARR.forEach(t => {
4040
cache[t] = null;
4141
});
4242

43-
const updateCacheQueue: {
44-
[x: string]: Array<{ resolve: () => void; reject: (error: any) => void }>;
45-
} = {};
43+
const updateCacheQueue: Record<string, Promise<void>> = {};
4644

47-
async function updateCache(type: TABLE_NAMES): Promise<void> {
48-
return new Promise((resolve, reject) => {
49-
// 如果正在Update,则放到回调组里面
50-
if (typeof updateCacheQueue[type] !== 'undefined') {
51-
updateCacheQueue[type].push({ resolve, reject });
52-
return;
53-
} else {
54-
updateCacheQueue[type] = [{ resolve, reject }];
55-
}
45+
function updateCache(type: TABLE_NAMES): Promise<void> {
46+
if (typeof updateCacheQueue[type] !== 'undefined') {
47+
return updateCacheQueue[type];
48+
}
49+
50+
const p = new Promise<void>((resolve, reject) => {
5651
getDatabase()
5752
.then(db => {
5853
const tx = db.transaction([type], 'readonly');
@@ -73,20 +68,21 @@ async function updateCache(type: TABLE_NAMES): Promise<void> {
7368
cursor.continue();
7469
} else {
7570
cache[type] = all;
76-
updateCacheQueue[type].forEach(it => {
77-
it.resolve();
78-
});
79-
delete updateCacheQueue[type];
71+
resolve();
8072
}
8173
};
8274
})
8375
.catch(e => {
84-
updateCacheQueue[type].forEach(it => {
85-
it.reject(e);
86-
});
76+
reject(e);
77+
})
78+
.finally(() => {
8779
delete updateCacheQueue[type];
8880
});
8981
});
82+
83+
updateCacheQueue[type] = p;
84+
85+
return p;
9086
}
9187

9288
function filter(fromRules: InitdRule[], options?: RuleFilterOptions) {

src/pages/background/request-handler/dnr-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ class DNRRequestHandler {
313313
type: 'warning',
314314
title: t('init_rule_failed'),
315315
content: `Rule: [${originalRule.id}] ${originalRule.name}\nError: ${(e as Error).message}`,
316-
more: `Rule: ${JSON.stringify(rule)}\nDNR Rule: ${JSON.stringify(rule)}`,
316+
more: `Rule: ${JSON.stringify(originalRule)}\nDNR Rule: ${JSON.stringify(rule)}`,
317317
});
318318
}
319319
}

0 commit comments

Comments
 (0)