@@ -4,7 +4,7 @@ use crate::{
4
4
app_size_handler:: AppSizeHandler ,
5
5
args:: Args ,
6
6
column:: Columns ,
7
- decks:: { Decks , DecksCache } ,
7
+ decks:: { Decks , DecksCache , FALLBACK_PUBKEY } ,
8
8
draft:: Drafts ,
9
9
filter:: FilterState ,
10
10
frame_history:: FrameHistory ,
@@ -450,36 +450,37 @@ impl Damus {
450
450
. as_ref ( )
451
451
. map ( |a| a. pubkey . bytes ( ) ) ;
452
452
453
- let decks_cache = if parsed_args. columns . is_empty ( ) {
454
- if let Some ( decks_cache) = storage:: load_decks_cache ( & path, & ndb) {
455
- info ! ( "Using decks cache from disk" ) ;
456
- decks_cache
457
- } else {
458
- info ! ( "Could read not decks cache from disk" ) ;
459
- let mut cache = DecksCache :: new_with_demo_config ( & ndb) ;
460
- for account in accounts. get_accounts ( ) {
461
- cache. add_deck_default ( account. pubkey ) ;
462
- }
463
- set_demo ( & mut cache, & ndb, & mut accounts, & mut unknown_ids) ;
464
-
465
- cache
466
- }
467
- } else {
453
+ let decks_cache = if !parsed_args. columns . is_empty ( ) {
454
+ info ! ( "DecksCache: loading from command line arguments" ) ;
468
455
let mut columns: Columns = Columns :: new ( ) ;
469
456
for col in parsed_args. columns {
470
457
if let Some ( timeline) = col. into_timeline ( & ndb, account) {
471
458
columns. add_new_timeline_column ( timeline) ;
472
459
}
473
460
}
474
461
475
- let mut decks_cache = DecksCache :: default ( ) ;
476
- let mut decks = Decks :: default ( ) ;
477
- * decks. active_mut ( ) . columns_mut ( ) = columns;
478
-
479
- if let Some ( acc) = account {
480
- decks_cache. add_decks ( Pubkey :: new ( * acc) , decks) ;
481
- }
462
+ columns_to_decks_cache ( columns, account)
463
+ } else if let Some ( decks_cache) = storage:: load_decks_cache ( & path, & ndb) {
464
+ info ! (
465
+ "DecksCache: loading from disk {}" ,
466
+ crate :: storage:: DECKS_CACHE_FILE
467
+ ) ;
482
468
decks_cache
469
+ } else if let Some ( cols) = storage:: deserialize_columns ( & path, & ndb, account) {
470
+ info ! (
471
+ "DecksCache: loading from disk at depreciated location {}" ,
472
+ crate :: storage:: COLUMNS_FILE
473
+ ) ;
474
+ columns_to_decks_cache ( cols, account)
475
+ } else {
476
+ info ! ( "DecksCache: creating new with demo configuration" ) ;
477
+ let mut cache = DecksCache :: new_with_demo_config ( & ndb) ;
478
+ for account in accounts. get_accounts ( ) {
479
+ cache. add_deck_default ( account. pubkey ) ;
480
+ }
481
+ set_demo ( & mut cache, & ndb, & mut accounts, & mut unknown_ids) ;
482
+
483
+ cache
483
484
} ;
484
485
485
486
let debug = parsed_args. debug ;
@@ -823,3 +824,20 @@ pub fn set_demo(
823
824
. process_action ( unk_ids, ndb, & txn) ;
824
825
accounts. select_account ( accounts. num_accounts ( ) - 1 ) ;
825
826
}
827
+
828
+ fn columns_to_decks_cache ( cols : Columns , key : Option < & [ u8 ; 32 ] > ) -> DecksCache {
829
+ let mut account_to_decks: HashMap < Pubkey , Decks > = Default :: default ( ) ;
830
+ let decks = Decks :: new ( crate :: decks:: Deck :: new_with_columns (
831
+ crate :: decks:: Deck :: default ( ) . icon ,
832
+ "My Deck" . to_owned ( ) ,
833
+ cols,
834
+ ) ) ;
835
+
836
+ let account = if let Some ( key) = key {
837
+ Pubkey :: new ( * key)
838
+ } else {
839
+ Pubkey :: from_hex ( FALLBACK_PUBKEY ) . unwrap ( )
840
+ } ;
841
+ account_to_decks. insert ( account, decks) ;
842
+ DecksCache :: new ( account_to_decks)
843
+ }
0 commit comments