From 85b57e6c39367450438ceb4b32d212cf3090d3e7 Mon Sep 17 00:00:00 2001 From: Alexandra Date: Thu, 29 May 2025 16:53:31 -0600 Subject: [PATCH] make fuzzy metadata search happen after all other database operations have settled. --- lib/metadatasearch.js | 11 ++++++----- lib/models/metadata.js | 2 +- server.js | 1 + 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/metadatasearch.js b/lib/metadatasearch.js index 461f5a8..eeda3a9 100644 --- a/lib/metadatasearch.js +++ b/lib/metadatasearch.js @@ -66,7 +66,7 @@ export default class MetadataSearch { this.platformMap = JSON.parse(readFileSync(mapFilePath, "utf8")); if (this.accessToken) { this.authorized = true; - this.syncAllMetadata(); + this.matchAllMetadata(); return; } } @@ -110,7 +110,7 @@ export default class MetadataSearch { } } - async matchAllMetadata() { + async matchAllMetadata(fuzzy = false) { let games = await File.findAndCountAll({ where: { nongame: false, @@ -154,14 +154,15 @@ export default class MetadataSearch { await game.save(); await md.save(); found++; - } else { + } else if (fuzzy) { //this is much slower and should only be used if the faster full text search can't find it. - let metadata = Metadata.fuzzySearchByText( + let metadata = await Metadata.fuzzySearchByText( this.normalizeName(game.filename), 0.6, game.category ); - if (metadata) { + if (metadata.length) { + let md = await Metadata.findByPk(metadata[0].id); await game.setDetails(md); await md.addFile(game); await game.save(); diff --git a/lib/models/metadata.js b/lib/models/metadata.js index 783c100..d5fd278 100644 --- a/lib/models/metadata.js +++ b/lib/models/metadata.js @@ -114,7 +114,7 @@ export default function (sequelize) { } const query = ` SELECT id FROM "Metadata" - WHERE SIMILARITY(title, $1) > $2 OR WHERE SIMILARITY(alternatetitles, $1) > $2 + WHERE SIMILARITY(title, $1) > $2 OR SIMILARITY(alternatetitles, $1) > $2 ${platformClause} ORDER BY length(title) ${limitClause} `; diff --git a/server.js b/server.js index f948776..b902ae1 100644 --- a/server.js +++ b/server.js @@ -87,6 +87,7 @@ async function getFilesJob() { await metadataSearch.syncAllMetadata(); } optimizeDatabaseKws(); + metadataSearch.matchAllMetadata(true) } function buildOptions(page, options) {