Skip to content

Commit 77a5c0c

Browse files
committed
add tasks to implement metadata and kws if they're empty (but block them by the main file update)
1 parent cc3750a commit 77a5c0c

File tree

1 file changed

+35
-8
lines changed

1 file changed

+35
-8
lines changed

server.js

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ let metadataMatchCount = 0;
4040
let indexPage = "pages/index";
4141
let flags = new Flag();
4242
let consoleIcons = new ConsoleIcons(emulatorsData);
43+
let updatingFiles = false;
4344
import { Op } from "sequelize";
4445

4546
// Initialize databases
@@ -80,6 +81,7 @@ let search = new Searcher(searchFields);
8081
let metadataManager = new MetadataManager();
8182

8283
async 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

111134
function buildOptions(page, options) {
@@ -588,3 +611,7 @@ if (
588611
}
589612

590613
cron.schedule("0 30 2 * * *", getFilesJob);
614+
615+
//run these tasks after to add new functions
616+
updateMetadata()
617+
updateKws()

0 commit comments

Comments
 (0)