Migrate away from item translations for itemByName GQL query
I'm not sure where this is used, my guess is it's for NeoBot?
This commit is contained in:
parent
f196e2d8fe
commit
8948b6567e
2 changed files with 8 additions and 18 deletions
|
@ -248,31 +248,21 @@ const buildItemByNameLoader = (db, loaders) =>
|
|||
const qs = names.map((_) => "?").join(", ");
|
||||
const normalizedNames = names.map((name) => name.trim().toLowerCase());
|
||||
const [rows] = await db.execute(
|
||||
{
|
||||
// NOTE: In our MySQL schema, this is a case-insensitive exact search.
|
||||
sql: `SELECT items.*, item_translations.* FROM item_translations
|
||||
INNER JOIN items ON items.id = item_translations.item_id
|
||||
WHERE name IN (${qs}) AND locale = "en"`,
|
||||
nestTables: true,
|
||||
},
|
||||
`SELECT * FROM items WHERE name IN (${qs})`,
|
||||
normalizedNames,
|
||||
);
|
||||
|
||||
const entitiesByName = new Map();
|
||||
for (const row of rows) {
|
||||
const item = normalizeRow(row.items);
|
||||
const itemTranslation = normalizeRow(row.item_translations);
|
||||
const item = normalizeRow(row);
|
||||
loaders.itemLoader.prime(item.id, item);
|
||||
loaders.itemTranslationLoader.prime(item.id, itemTranslation);
|
||||
|
||||
const normalizedName = itemTranslation.name.trim().toLowerCase();
|
||||
entitiesByName.set(normalizedName, { item, itemTranslation });
|
||||
const normalizedName = item.name.trim().toLowerCase();
|
||||
entitiesByName.set(normalizedName, item);
|
||||
}
|
||||
|
||||
return normalizedNames.map(
|
||||
(name) =>
|
||||
entitiesByName.get(name) || { item: null, itemTranslation: null },
|
||||
);
|
||||
return normalizedNames.map((name) => entitiesByName.get(name) || null);
|
||||
},
|
||||
{ cacheKeyFn: (name) => name.trim().toLowerCase() },
|
||||
);
|
||||
|
|
|
@ -743,12 +743,12 @@ const resolvers = {
|
|||
return ids.map((id) => ({ id }));
|
||||
},
|
||||
itemByName: async (_, { name }, { itemByNameLoader }) => {
|
||||
const { item } = await itemByNameLoader.load(name);
|
||||
const item = await itemByNameLoader.load(name);
|
||||
return item ? { id: item.id } : null;
|
||||
},
|
||||
itemsByName: async (_, { names }, { itemByNameLoader }) => {
|
||||
const items = await itemByNameLoader.loadMany(names);
|
||||
return items.map(({ item }) => (item ? { id: item.id } : null));
|
||||
return items.map((item) => (item ? { id: item.id } : null));
|
||||
},
|
||||
itemSearch: async (
|
||||
_,
|
||||
|
|
Loading…
Reference in a new issue