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:
parent
6fc508589a
commit
d621b4c1a7
2 changed files with 26 additions and 27 deletions
|
@ -196,7 +196,8 @@ const buildPetTypeLoader = (db) =>
|
|||
});
|
||||
|
||||
const buildPetTypeBySpeciesAndColorLoader = (db, loaders) =>
|
||||
new DataLoader(async (speciesAndColorPairs) => {
|
||||
new DataLoader(
|
||||
async (speciesAndColorPairs) => {
|
||||
const conditions = [];
|
||||
const values = [];
|
||||
for (const { speciesId, colorId } of speciesAndColorPairs) {
|
||||
|
@ -221,7 +222,9 @@ const buildPetTypeBySpeciesAndColorLoader = (db, loaders) =>
|
|||
return speciesAndColorPairs.map(({ speciesId, colorId }) =>
|
||||
entitiesBySpeciesAndColorPair.get(`${speciesId},${colorId}`)
|
||||
);
|
||||
});
|
||||
},
|
||||
{ cacheKeyFn: ({ speciesId, colorId }) => `${speciesId},${colorId}` }
|
||||
);
|
||||
|
||||
const buildSwfAssetLoader = (db) =>
|
||||
new DataLoader(async (swfAssetIds) => {
|
||||
|
|
|
@ -111,14 +111,10 @@ describe("Item", () => {
|
|||
],
|
||||
],
|
||||
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 [
|
||||
"54",
|
||||
"75",
|
||||
"54",
|
||||
"75",
|
||||
"54",
|
||||
"75",
|
||||
],
|
||||
],
|
||||
Array [
|
||||
|
|
Loading…
Reference in a new issue