fix caching for petTypeLoader

Oops, of course, we weren't actually taking proper advantage of the dataloader here! The queries got over-complicated, but more importantly, subsequent requests to the same loader would re-submit the query!

I noticed it in the SearchPanel operation, in this Honeycomb trace:
https://ui.honeycomb.io/openneo/datasets/dress-to-impress--2020-/trace/aMuhsTjQFZY
This commit is contained in:
Emi Matchu 2020-08-17 01:33:34 -07:00
parent 6fc508589a
commit d621b4c1a7
2 changed files with 26 additions and 27 deletions

View file

@ -196,7 +196,8 @@ const buildPetTypeLoader = (db) =>
}); });
const buildPetTypeBySpeciesAndColorLoader = (db, loaders) => const buildPetTypeBySpeciesAndColorLoader = (db, loaders) =>
new DataLoader(async (speciesAndColorPairs) => { new DataLoader(
async (speciesAndColorPairs) => {
const conditions = []; const conditions = [];
const values = []; const values = [];
for (const { speciesId, colorId } of speciesAndColorPairs) { for (const { speciesId, colorId } of speciesAndColorPairs) {
@ -221,7 +222,9 @@ const buildPetTypeBySpeciesAndColorLoader = (db, loaders) =>
return speciesAndColorPairs.map(({ speciesId, colorId }) => return speciesAndColorPairs.map(({ speciesId, colorId }) =>
entitiesBySpeciesAndColorPair.get(`${speciesId},${colorId}`) entitiesBySpeciesAndColorPair.get(`${speciesId},${colorId}`)
); );
}); },
{ cacheKeyFn: ({ speciesId, colorId }) => `${speciesId},${colorId}` }
);
const buildSwfAssetLoader = (db) => const buildSwfAssetLoader = (db) =>
new DataLoader(async (swfAssetIds) => { new DataLoader(async (swfAssetIds) => {

View file

@ -111,14 +111,10 @@ describe("Item", () => {
], ],
], ],
Array [ Array [
"SELECT * FROM pet_types WHERE (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?)", "SELECT * FROM pet_types WHERE (species_id = ? AND color_id = ?)",
Array [ Array [
"54", "54",
"75", "75",
"54",
"75",
"54",
"75",
], ],
], ],
Array [ Array [