@@ -40,6 +40,7 @@ let metadataMatchCount = 0;
4040let indexPage = "pages/index" ;
4141let flags = new Flag ( ) ;
4242let consoleIcons = new ConsoleIcons ( emulatorsData ) ;
43+ let updatingFiles = false ;
4344import { Op } from "sequelize" ;
4445
4546// Initialize databases
@@ -80,6 +81,7 @@ let search = new Searcher(searchFields);
8081let metadataManager = new MetadataManager ( ) ;
8182
8283async function getFilesJob ( ) {
84+ updatingFiles = true ;
8385 console . log ( "Updating the file list." ) ;
8486 let oldFileCount = fileCount || 0 ;
8587 fileCount = await getAllFiles ( categoryList ) ;
@@ -89,23 +91,44 @@ async function getFilesJob() {
8991 }
9092 crawlTime = Date . now ( ) ;
9193 console . log ( `Finished updating file list. ${ fileCount } found.` ) ;
92- if ( ( await Metadata . count ( ) ) < ( await metadataManager . getIGDBGamesCount ( ) ) ) {
93- await metadataManager . syncAllMetadata ( ) ;
94- metadataMatchCount = await File . count ( {
95- where : { detailsId : { [ Op . ne ] : null } } ,
96- } ) ;
97- }
9894 if ( fileCount > oldFileCount ) {
99- await metadataManager . matchAllMetadata ( ) ;
95+ if (
96+ ( await Metadata . count ( ) ) < ( await metadataManager . getIGDBGamesCount ( ) )
97+ ) {
98+ await metadataManager . syncAllMetadata ( ) ;
99+ await metadataManager . matchAllMetadata ( ) ;
100+ metadataMatchCount = await File . count ( {
101+ where : { detailsId : { [ Op . ne ] : null } } ,
102+ } ) ;
103+ }
104+ await optimizeDatabaseKws ( ) ;
100105 }
101- await optimizeDatabaseKws ( ) ;
102106 //this is less important and needs to run last.
103107 if ( fileCount > oldFileCount ) {
104108 metadataManager . matchAllMetadata ( true ) ;
105109 }
106110 metadataMatchCount = await File . count ( {
107111 where : { detailsId : { [ Op . ne ] : null } } ,
108112 } ) ;
113+ updatingFiles = false ;
114+ }
115+
116+ async function updateMetadata ( ) {
117+ if ( updatingFiles ) return ;
118+ if ( ( await Metadata . count ( ) ) < ( await metadataManager . getIGDBGamesCount ( ) ) ) {
119+ await metadataManager . syncAllMetadata ( ) ;
120+ await metadataManager . matchAllMetadata ( ) ;
121+ metadataMatchCount = await File . count ( {
122+ where : { detailsId : { [ Op . ne ] : null } } ,
123+ } ) ;
124+ }
125+ }
126+
127+ async function updateKws ( ) {
128+ if ( updatingFiles ) return ;
129+ if ( ! await File . count ( { where : { filenamekws : { [ Op . ne ] : null } } } ) ) {
130+ await optimizeDatabaseKws ( ) ;
131+ }
109132}
110133
111134function buildOptions ( page , options ) {
588611}
589612
590613cron . schedule ( "0 30 2 * * *" , getFilesJob ) ;
614+
615+ //run these tasks after to add new functions
616+ updateMetadata ( )
617+ updateKws ( )
0 commit comments