Improved tag matching query efficiency, should fix some big scrape failures.

This commit is contained in:
DebaucheryLibrarian
2026-10-21 05:20:19 +02:00
parent b8ad6bb10b
commit 40d56c515d
+5 -4
View File
@@ -79,13 +79,14 @@ function withRelations(queryBuilder, withMedia) {
}
async function matchTags(rawTags) {
const tags = rawTags
.map((tag) => tag?.trim().match(/[a-z0-9()-]+/ig)?.join(' ').toLowerCase())
.filter(Boolean);
const tags = Array.from(new Set(rawTags
.map((tag) => (typeof tag === 'string' ? tag : null)?.trim().match(/[a-z0-9()-]+/ig)?.join(' ').toLowerCase())
.filter(Boolean)));
// array binding, large batches can easily exceed the bindings limit otherwise
const tagEntries = await knex('tags')
.select('tags.id', 'tags.name', 'tags.alias_for', 'tags.implied_tag_ids')
.whereIn(knex.raw('lower(tags.name)'), tags);
.whereRaw('lower(tags.name) = ANY(:tags)', { tags });
const tagIdsBySlug = tagEntries
.reduce((acc, tag) => ({