Improved tag matching query efficiency, should fix some big scrape failures.
This commit is contained in:
+5
-4
@@ -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) => ({
|
||||
|
||||
Reference in New Issue
Block a user