diff --git a/src/server/loaders.js b/src/server/loaders.js index 13939c2..482dcb7 100644 --- a/src/server/loaders.js +++ b/src/server/loaders.js @@ -121,7 +121,7 @@ const buildItemTranslationLoader = (db) => ); }); -const buildItemSearchLoader = (db) => +const buildItemSearchLoader = (db, loaders) => new DataLoader(async (queries) => { // This isn't actually optimized as a batch query, we're just using a // DataLoader API consistency with our other loaders! @@ -138,6 +138,10 @@ const buildItemSearchLoader = (db) => const entities = rows.map(normalizeRow); + for (const item of entities) { + loaders.itemLoader.prime(item.id, item); + } + return entities; }); @@ -146,7 +150,7 @@ const buildItemSearchLoader = (db) => return responses; }); -const buildItemSearchToFitLoader = (db) => +const buildItemSearchToFitLoader = (db, loaders) => new DataLoader(async (queryAndBodyIdPairs) => { // This isn't actually optimized as a batch query, we're just using a // DataLoader API consistency with our other loaders! @@ -171,6 +175,10 @@ const buildItemSearchToFitLoader = (db) => const entities = rows.map(normalizeRow); + for (const item of entities) { + loaders.itemLoader.prime(item.id, item); + } + return entities; } ); @@ -407,8 +415,8 @@ function buildLoaders(db) { loaders.colorTranslationLoader = buildColorTranslationLoader(db); loaders.itemLoader = buildItemLoader(db); loaders.itemTranslationLoader = buildItemTranslationLoader(db); - loaders.itemSearchLoader = buildItemSearchLoader(db); - loaders.itemSearchToFitLoader = buildItemSearchToFitLoader(db); + loaders.itemSearchLoader = buildItemSearchLoader(db, loaders); + loaders.itemSearchToFitLoader = buildItemSearchToFitLoader(db, loaders); loaders.petTypeLoader = buildPetTypeLoader(db); loaders.petTypeBySpeciesAndColorLoader = buildPetTypeBySpeciesAndColorLoader( db, diff --git a/src/server/query-tests/ItemSearch.test.js b/src/server/query-tests/ItemSearch.test.js index b54debe..1e37a24 100644 --- a/src/server/query-tests/ItemSearch.test.js +++ b/src/server/query-tests/ItemSearch.test.js @@ -101,6 +101,11 @@ describe("ItemSearch", () => { items { id name + appearanceOn(speciesId: "54", colorId: "75") { + layers { + id + } + } } } } @@ -135,6 +140,35 @@ describe("ItemSearch", () => { 0, ], ], + Array [ + "SELECT sa.*, rel.parent_id FROM swf_assets sa + INNER JOIN parents_swf_assets rel ON + rel.parent_type = \\"Item\\" AND + rel.swf_asset_id = sa.id + WHERE (rel.parent_id = ? AND (sa.body_id = ? OR sa.body_id = 0)) OR (rel.parent_id = ? AND (sa.body_id = ? OR sa.body_id = 0)) OR (rel.parent_id = ? AND (sa.body_id = ? OR sa.body_id = 0)) OR (rel.parent_id = ? AND (sa.body_id = ? OR sa.body_id = 0)) OR (rel.parent_id = ? AND (sa.body_id = ? OR sa.body_id = 0)) OR (rel.parent_id = ? AND (sa.body_id = ? OR sa.body_id = 0)) OR (rel.parent_id = ? AND (sa.body_id = ? OR sa.body_id = 0)) OR (rel.parent_id = ? AND (sa.body_id = ? OR sa.body_id = 0)) OR (rel.parent_id = ? AND (sa.body_id = ? OR sa.body_id = 0)) OR (rel.parent_id = ? AND (sa.body_id = ? OR sa.body_id = 0))", + Array [ + "74967", + "180", + "49026", + "180", + "67242", + "180", + "64177", + "180", + "69995", + "180", + "62375", + "180", + "56654", + "180", + "62322", + "180", + "58733", + "180", + "80401", + "180", + ], + ], ] `); }); diff --git a/src/server/query-tests/__snapshots__/ItemSearch.test.js.snap b/src/server/query-tests/__snapshots__/ItemSearch.test.js.snap index 3b8b4f1..a211ec2 100644 --- a/src/server/query-tests/__snapshots__/ItemSearch.test.js.snap +++ b/src/server/query-tests/__snapshots__/ItemSearch.test.js.snap @@ -101,42 +101,121 @@ Object { "itemSearchToFit": Object { "items": Array [ Object { + "appearanceOn": Object { + "layers": Array [ + Object { + "id": "395669", + }, + ], + }, "id": "74967", "name": "17th Birthday Party Hat", }, Object { + "appearanceOn": Object { + "layers": Array [ + Object { + "id": "79262", + }, + ], + }, "id": "49026", "name": "Abominable Snowman Hat", }, Object { + "appearanceOn": Object { + "layers": Array [ + Object { + "id": "248670", + }, + Object { + "id": "248671", + }, + ], + }, "id": "67242", "name": "Accessories Shop Wig and Hat", }, Object { + "appearanceOn": Object { + "layers": Array [ + Object { + "id": "207062", + }, + ], + }, "id": "64177", "name": "Acorn Hat", }, Object { + "appearanceOn": Object { + "layers": Array [ + Object { + "id": "293566", + }, + Object { + "id": "293567", + }, + ], + }, "id": "69995", "name": "Adventure in Pastel Hat and Wig", }, Object { + "appearanceOn": Object { + "layers": Array [ + Object { + "id": "186927", + }, + ], + }, "id": "62375", "name": "Altador Cup Trophy Hat", }, Object { + "appearanceOn": Object { + "layers": Array [ + Object { + "id": "392019", + }, + ], + }, "id": "56654", "name": "Altador Team Hat", }, Object { + "appearanceOn": Object { + "layers": Array [ + Object { + "id": "201066", + }, + ], + }, "id": "62322", "name": "Altador Team Jester Hat", }, Object { + "appearanceOn": Object { + "layers": Array [ + Object { + "id": "144021", + }, + ], + }, "id": "58733", "name": "Apple Bobbing Bart Hat", }, Object { + "appearanceOn": Object { + "layers": Array [ + Object { + "id": "495043", + }, + Object { + "id": "495044", + }, + ], + }, "id": "80401", "name": "Aurricks Finest Hat", },