Migrate away from item translations for item search

This commit is contained in:
Emi Matchu 2024-02-20 16:31:45 -08:00
parent 62531cfe34
commit c455617362

View file

@ -308,7 +308,9 @@ function buildItemSearchConditions({
continue; continue;
} }
const condition = isNegative ? "t.name NOT LIKE ?" : "t.name LIKE ?"; const condition = isNegative
? "items.name NOT LIKE ?"
: "items.name LIKE ?";
const matcher = "%" + word.replace(/_%/g, "\\$0") + "%"; const matcher = "%" + word.replace(/_%/g, "\\$0") + "%";
wordMatchConditions.push(condition); wordMatchConditions.push(condition);
@ -336,7 +338,6 @@ function buildItemSearchConditions({
: []; : [];
const queryJoins = ` const queryJoins = `
INNER JOIN item_translations t ON t.item_id = items.id
INNER JOIN parents_swf_assets rel INNER JOIN parents_swf_assets rel
ON rel.parent_type = "Item" AND rel.parent_id = items.id ON rel.parent_type = "Item" AND rel.parent_id = items.id
INNER JOIN swf_assets ON rel.swf_asset_id = swf_assets.id INNER JOIN swf_assets ON rel.swf_asset_id = swf_assets.id
@ -346,7 +347,7 @@ function buildItemSearchConditions({
const queryConditions = ` const queryConditions = `
(${wordMatchCondition}) AND (${bodyIdCondition}) AND (${wordMatchCondition}) AND (${bodyIdCondition}) AND
(${zoneIdsCondition}) AND (${itemKindCondition}) AND (${zoneIdsCondition}) AND (${itemKindCondition}) AND
(${currentUserCondition}) AND t.locale = "en" (${currentUserCondition})
`; `;
const queryConditionValues = [ const queryConditionValues = [
...wordMatchValues, ...wordMatchValues,
@ -430,10 +431,10 @@ const buildItemSearchItemsLoader = (db, loaders) =>
const [rows] = await db.execute( const [rows] = await db.execute(
` `
SELECT DISTINCT items.*, t.name FROM items SELECT DISTINCT items.* FROM items
${queryJoins} ${queryJoins}
WHERE ${queryConditions} WHERE ${queryConditions}
ORDER BY t.name ORDER BY items.name
LIMIT ? OFFSET ? LIMIT ? OFFSET ?
`, `,
[...queryConditionValues, actualLimit, actualOffset], [...queryConditionValues, actualLimit, actualOffset],