File tree Expand file tree Collapse file tree 1 file changed +19
-14
lines changed Expand file tree Collapse file tree 1 file changed +19
-14
lines changed Original file line number Diff line number Diff line change @@ -548,20 +548,6 @@ class Setting extends BaseModel {
548
548
this . cache_ = [ ] ;
549
549
const rows : CacheItem [ ] = await this . modelSelectAll ( 'SELECT * FROM settings' ) ;
550
550
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
- } ;
565
551
566
552
// Keys in the database takes precedence over keys in the keychain because
567
553
// they are more likely to be up to date (saving to keychain can fail, but
@@ -602,6 +588,25 @@ class Setting extends BaseModel {
602
588
}
603
589
}
604
590
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
+
605
610
pushItemsToCache ( rows ) ;
606
611
pushItemsToCache ( secureItems ) ;
607
612
pushItemsToCache ( itemsFromFile ) ;
You can’t perform that action at this time.
0 commit comments