itemSearchLoaders should prime item loader cache

Another perf issue I noticed in Honeycomb for the SearchPanel operation! We re-load the items again by ID, even though we already got them by name. Let's stop that!
https://ui.honeycomb.io/openneo/datasets/dress-to-impress--2020-/trace/aMuhsTjQFZY
This commit is contained in:
Emi Matchu 2020-08-17 01:41:38 -07:00
parent d621b4c1a7
commit b300718b4a
3 changed files with 125 additions and 4 deletions

View file

@ -121,7 +121,7 @@ const buildItemTranslationLoader = (db) =>
); );
}); });
const buildItemSearchLoader = (db) => const buildItemSearchLoader = (db, loaders) =>
new DataLoader(async (queries) => { new DataLoader(async (queries) => {
// This isn't actually optimized as a batch query, we're just using a // This isn't actually optimized as a batch query, we're just using a
// DataLoader API consistency with our other loaders! // DataLoader API consistency with our other loaders!
@ -138,6 +138,10 @@ const buildItemSearchLoader = (db) =>
const entities = rows.map(normalizeRow); const entities = rows.map(normalizeRow);
for (const item of entities) {
loaders.itemLoader.prime(item.id, item);
}
return entities; return entities;
}); });
@ -146,7 +150,7 @@ const buildItemSearchLoader = (db) =>
return responses; return responses;
}); });
const buildItemSearchToFitLoader = (db) => const buildItemSearchToFitLoader = (db, loaders) =>
new DataLoader(async (queryAndBodyIdPairs) => { new DataLoader(async (queryAndBodyIdPairs) => {
// This isn't actually optimized as a batch query, we're just using a // This isn't actually optimized as a batch query, we're just using a
// DataLoader API consistency with our other loaders! // DataLoader API consistency with our other loaders!
@ -171,6 +175,10 @@ const buildItemSearchToFitLoader = (db) =>
const entities = rows.map(normalizeRow); const entities = rows.map(normalizeRow);
for (const item of entities) {
loaders.itemLoader.prime(item.id, item);
}
return entities; return entities;
} }
); );
@ -407,8 +415,8 @@ function buildLoaders(db) {
loaders.colorTranslationLoader = buildColorTranslationLoader(db); loaders.colorTranslationLoader = buildColorTranslationLoader(db);
loaders.itemLoader = buildItemLoader(db); loaders.itemLoader = buildItemLoader(db);
loaders.itemTranslationLoader = buildItemTranslationLoader(db); loaders.itemTranslationLoader = buildItemTranslationLoader(db);
loaders.itemSearchLoader = buildItemSearchLoader(db); loaders.itemSearchLoader = buildItemSearchLoader(db, loaders);
loaders.itemSearchToFitLoader = buildItemSearchToFitLoader(db); loaders.itemSearchToFitLoader = buildItemSearchToFitLoader(db, loaders);
loaders.petTypeLoader = buildPetTypeLoader(db); loaders.petTypeLoader = buildPetTypeLoader(db);
loaders.petTypeBySpeciesAndColorLoader = buildPetTypeBySpeciesAndColorLoader( loaders.petTypeBySpeciesAndColorLoader = buildPetTypeBySpeciesAndColorLoader(
db, db,

View file

@ -101,6 +101,11 @@ describe("ItemSearch", () => {
items { items {
id id
name name
appearanceOn(speciesId: "54", colorId: "75") {
layers {
id
}
}
} }
} }
} }
@ -135,6 +140,35 @@ describe("ItemSearch", () => {
0, 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",
],
],
] ]
`); `);
}); });

View file

@ -101,42 +101,121 @@ Object {
"itemSearchToFit": Object { "itemSearchToFit": Object {
"items": Array [ "items": Array [
Object { Object {
"appearanceOn": Object {
"layers": Array [
Object {
"id": "395669",
},
],
},
"id": "74967", "id": "74967",
"name": "17th Birthday Party Hat", "name": "17th Birthday Party Hat",
}, },
Object { Object {
"appearanceOn": Object {
"layers": Array [
Object {
"id": "79262",
},
],
},
"id": "49026", "id": "49026",
"name": "Abominable Snowman Hat", "name": "Abominable Snowman Hat",
}, },
Object { Object {
"appearanceOn": Object {
"layers": Array [
Object {
"id": "248670",
},
Object {
"id": "248671",
},
],
},
"id": "67242", "id": "67242",
"name": "Accessories Shop Wig and Hat", "name": "Accessories Shop Wig and Hat",
}, },
Object { Object {
"appearanceOn": Object {
"layers": Array [
Object {
"id": "207062",
},
],
},
"id": "64177", "id": "64177",
"name": "Acorn Hat", "name": "Acorn Hat",
}, },
Object { Object {
"appearanceOn": Object {
"layers": Array [
Object {
"id": "293566",
},
Object {
"id": "293567",
},
],
},
"id": "69995", "id": "69995",
"name": "Adventure in Pastel Hat and Wig", "name": "Adventure in Pastel Hat and Wig",
}, },
Object { Object {
"appearanceOn": Object {
"layers": Array [
Object {
"id": "186927",
},
],
},
"id": "62375", "id": "62375",
"name": "Altador Cup Trophy Hat", "name": "Altador Cup Trophy Hat",
}, },
Object { Object {
"appearanceOn": Object {
"layers": Array [
Object {
"id": "392019",
},
],
},
"id": "56654", "id": "56654",
"name": "Altador Team Hat", "name": "Altador Team Hat",
}, },
Object { Object {
"appearanceOn": Object {
"layers": Array [
Object {
"id": "201066",
},
],
},
"id": "62322", "id": "62322",
"name": "Altador Team Jester Hat", "name": "Altador Team Jester Hat",
}, },
Object { Object {
"appearanceOn": Object {
"layers": Array [
Object {
"id": "144021",
},
],
},
"id": "58733", "id": "58733",
"name": "Apple Bobbing Bart Hat", "name": "Apple Bobbing Bart Hat",
}, },
Object { Object {
"appearanceOn": Object {
"layers": Array [
Object {
"id": "495043",
},
Object {
"id": "495044",
},
],
},
"id": "80401", "id": "80401",
"name": "Aurricks Finest Hat", "name": "Aurricks Finest Hat",
}, },