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) {
|
async function matchTags(rawTags) {
|
||||||
const tags = rawTags
|
const tags = Array.from(new Set(rawTags
|
||||||
.map((tag) => tag?.trim().match(/[a-z0-9()-]+/ig)?.join(' ').toLowerCase())
|
.map((tag) => (typeof tag === 'string' ? tag : null)?.trim().match(/[a-z0-9()-]+/ig)?.join(' ').toLowerCase())
|
||||||
.filter(Boolean);
|
.filter(Boolean)));
|
||||||
|
|
||||||
|
// array binding, large batches can easily exceed the bindings limit otherwise
|
||||||
const tagEntries = await knex('tags')
|
const tagEntries = await knex('tags')
|
||||||
.select('tags.id', 'tags.name', 'tags.alias_for', 'tags.implied_tag_ids')
|
.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
|
const tagIdsBySlug = tagEntries
|
||||||
.reduce((acc, tag) => ({
|
.reduce((acc, tag) => ({
|
||||||
|
|||||||
Reference in New Issue
Block a user