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:
parent
d621b4c1a7
commit
b300718b4a
3 changed files with 125 additions and 4 deletions
|
@ -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,
|
||||
|
|
|
@ -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",
|
||||
],
|
||||
],
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
|
|
@ -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",
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue