Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9969663

Browse files
Chore: Desktop: Add extra check to try to prevent duplicate setting key warning (laurent22#11084)
1 parent be5a6c1 commit 9969663

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

packages/lib/models/Setting.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -548,20 +548,6 @@ class Setting extends BaseModel {
548548
this.cache_ = [];
549549
const rows: CacheItem[] = await this.modelSelectAll('SELECT * FROM settings');
550550

551-
this.cache_ = [];
552-
553-
const pushItemsToCache = (items: CacheItem[]) => {
554-
for (let i = 0; i < items.length; i++) {
555-
const c = items[i];
556-
557-
if (!this.keyExists(c.key)) continue;
558-
559-
c.value = this.formatValue(c.key, c.value);
560-
c.value = this.filterValue(c.key, c.value);
561-
562-
this.cache_.push(c);
563-
}
564-
};
565551

566552
// Keys in the database takes precedence over keys in the keychain because
567553
// they are more likely to be up to date (saving to keychain can fail, but
@@ -602,6 +588,25 @@ class Setting extends BaseModel {
602588
}
603589
}
604590

591+
592+
this.cache_ = [];
593+
const cachedKeys = new Set();
594+
const pushItemsToCache = (items: CacheItem[]) => {
595+
for (let i = 0; i < items.length; i++) {
596+
const c = items[i];
597+
598+
// Avoid duplicating keys -- doing so causes save issues.
599+
if (cachedKeys.has(c.key)) continue;
600+
if (!this.keyExists(c.key)) continue;
601+
602+
c.value = this.formatValue(c.key, c.value);
603+
c.value = this.filterValue(c.key, c.value);
604+
605+
cachedKeys.add(c.key);
606+
this.cache_.push(c);
607+
}
608+
};
609+
605610
pushItemsToCache(rows);
606611
pushItemsToCache(secureItems);
607612
pushItemsToCache(itemsFromFile);

0 commit comments

Comments
 (0)