diff --git a/src/tags.js b/src/tags.js index d74dcb51..7ec46549 100755 --- a/src/tags.js +++ b/src/tags.js @@ -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) => ({