@@ -546,58 +546,40 @@ def list_missing_files(self, db_files):
546
546
files .update (external ['files' ])
547
547
return {f : d for f , d in files .items () if f not in db_files }
548
548
549
- def zip_summary (self , zip_id ) -> Optional [Dict [str , Any ]]:
550
- files = {}
551
- folders = {}
552
- for file_path , file_description in self ._aggregated_summary ['files' ].items ():
553
- if 'zip_id' in file_description and file_description ['zip_id' ] == zip_id :
554
- # @TODO: This if should not be necessary if we store all the zip information on the store
555
- # Explicit asking for games and cheats is a hack, as this should only be declared in
556
- # the database information. Remove ASAP
557
- if file_path .startswith ('games' ) or file_path .startswith ('cheats' ):
558
- files ['|' + file_path ] = file_description
559
- else :
560
- files [file_path ] = file_description
561
-
562
- for folder_path , folder_description in self ._aggregated_summary ['folders' ].items ():
563
- if 'zip_id' in folder_description and folder_description ['zip_id' ] == zip_id :
564
- # @TODO: This if should not be necessary if we store all the zip information on the store
565
- # Explicit asking for games and cheats is a hack, as this should only be declared in
566
- # the database information. Remove ASAP
567
- if folder_path .startswith ('games' ) or folder_path .startswith ('cheats' ):
568
- folders ['|' + folder_path ] = folder_description
569
- else :
570
- folders [folder_path ] = folder_description
571
-
572
- for zip_id , zip_description in self ._store .get ('filtered_zip_data' , {}).items ():
573
- if zip_id != zip_id :
574
- continue
549
+ def zip_summaries (self ) -> dict [str , Any ]:
550
+ grouped = defaultdict (lambda : {'files' : {}, 'folders' : {}})
551
+
552
+ # @TODO: This if startswith('games') should be removed when we store all the zip information on the store
553
+ # Explicit asking for games is a hack, as this should only be declared in the database information. Remove ASAP
554
+
555
+ for fp , fd in self ._store .get ('files' , {}).items ():
556
+ if 'zip_id' not in fd : continue
557
+ grouped [fd ['zip_id' ]]['files' ][f'|{ fp } ' if fp .startswith ('games' ) else fp ] = fd
558
+
559
+ for dp , dd in self ._store .get ('folders' , {}).items ():
560
+ if 'zip_id' not in dd : continue
561
+ grouped [dd ['zip_id' ]]['folders' ][f'|{ dp } ' if dp .startswith ('games' ) else dp ] = dd
562
+
563
+ for summary in self ._store .get ('external' , {}).values ():
564
+ for fp , fd in summary .get ('files' , {}).items ():
565
+ if 'zip_id' not in fd : continue
566
+ grouped [fd ['zip_id' ]]['files' ][f'|{ fp } ' if fp .startswith ('games' ) else fp ] = fd
567
+
568
+ for summary in self ._store .get ('external' , {}).values ():
569
+ for dp , dd in summary .get ('folders' , {}).items ():
570
+ if 'zip_id' not in dd : continue
571
+ grouped [dd ['zip_id' ]]['folders' ][f'|{ dp } ' if dp .startswith ('games' ) else dp ] = dd
572
+
573
+ for zip_id , summary in self ._store .get ('filtered_zip_data' , {}).items ():
574
+ for fp , fd in summary .get ('files' , {}).items ():
575
+ grouped [zip_id ]['files' ][f'|{ fp } ' if fp .startswith ('games' ) else fp ] = fd
576
+ for dp , dd in summary .get ('folders' , {}).items ():
577
+ grouped [zip_id ]['folders' ][f'|{ dp } ' if dp .startswith ('games' ) else dp ] = dd
578
+
579
+ for zip_id , data in grouped .items ():
580
+ data ['hash' ] = self ._store .get ('zips' , {}).get (zip_id , {}).get ('summary_file' , {}).get ('hash' , NO_HASH_IN_STORE_CODE )
575
581
576
- for file_path , file_description in zip_description ['files' ].items ():
577
- if 'zip_id' in file_description and file_description ['zip_id' ] == zip_id :
578
- # @TODO: This if should not be necessary if we store all the zip information on the store
579
- # Explicit asking for games and cheats is a hack, as this should only be declared in
580
- # the database information. Remove ASAP
581
- if file_path .startswith ('games' ) or file_path .startswith ('cheats' ):
582
- files ['|' + file_path ] = file_description
583
- else :
584
- files [file_path ] = file_description
585
-
586
- for folder_path , folder_description in zip_description ['folders' ].items ():
587
- if 'zip_id' in folder_description and folder_description ['zip_id' ] == zip_id :
588
- # @TODO: This if should not be necessary if we store all the zip information on the store
589
- # Explicit asking for games and cheats is a hack, as this should only be declared in
590
- # the database information. Remove ASAP
591
- if folder_path .startswith ('games' ) or folder_path .startswith ('cheats' ):
592
- folders ['|' + folder_path ] = folder_description
593
- else :
594
- folders [folder_path ] = folder_description
595
-
596
- if len (files ) == 0 and len (folders ) == 0 :
597
- return None
598
-
599
- summary_hash = self ._store .get ('zips' , {}).get (zip_id , {}).get ('summary_file' , {}).get ('hash' , NO_HASH_IN_STORE_CODE )
600
- return {'files' : files , 'folders' : folders , 'hash' : summary_hash }
582
+ return grouped
601
583
602
584
@property
603
585
def filtered_zip_data (self ):
0 commit comments