perf upgrade for UserItemsPage
I knowingly wrote this less performant at first. And indeed, it was slow—like 2sec of main thread time! Turn that O(mn) into O(n) pls!
This commit is contained in:
parent
a7e32232e2
commit
8a06ac7fb9
2 changed files with 19 additions and 10 deletions
|
@ -69,7 +69,7 @@ Object {
|
||||||
"name": "Blue Jelly Tiara",
|
"name": "Blue Jelly Tiara",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
"name": "(Not in a list)",
|
"name": "Not in a list",
|
||||||
"ownsOrWantsItems": "OWNS",
|
"ownsOrWantsItems": "OWNS",
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
|
@ -81,7 +81,7 @@ Object {
|
||||||
"name": "Altador Cup Background - Kreludor",
|
"name": "Altador Cup Background - Kreludor",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
"name": "(Not in a list)",
|
"name": "Not in a list",
|
||||||
"ownsOrWantsItems": "WANTS",
|
"ownsOrWantsItems": "WANTS",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
@ -136,12 +136,25 @@ const resolvers = {
|
||||||
userLoader.load(id),
|
userLoader.load(id),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const hangersByList = new Map(closetLists.map((l) => [l.id, []]));
|
||||||
|
const defaultListOwnedHangers = [];
|
||||||
|
const defaultListWantedHangers = [];
|
||||||
|
for (const hanger of allClosetHangers) {
|
||||||
|
if (hanger.listId) {
|
||||||
|
hangersByList.get(hanger.listId).push(hanger);
|
||||||
|
} else if (hanger.owned) {
|
||||||
|
defaultListOwnedHangers.push(hanger);
|
||||||
|
} else {
|
||||||
|
defaultListWantedHangers.push(hanger);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const closetListNodes = closetLists
|
const closetListNodes = closetLists
|
||||||
.filter((closetList) => isCurrentUser || closetList.visibility >= 1)
|
.filter((closetList) => isCurrentUser || closetList.visibility >= 1)
|
||||||
.map((closetList) => ({
|
.map((closetList) => ({
|
||||||
id: closetList.id,
|
id: closetList.id,
|
||||||
items: allClosetHangers
|
items: hangersByList
|
||||||
.filter((h) => h.listId === closetList.id)
|
.get(closetList.id)
|
||||||
.map((h) => ({ id: h.itemId })),
|
.map((h) => ({ id: h.itemId })),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -150,9 +163,7 @@ const resolvers = {
|
||||||
isDefaultList: true,
|
isDefaultList: true,
|
||||||
userId: id,
|
userId: id,
|
||||||
ownsOrWantsItems: "OWNS",
|
ownsOrWantsItems: "OWNS",
|
||||||
items: allClosetHangers
|
items: defaultListOwnedHangers.map((h) => ({ id: h.itemId })),
|
||||||
.filter((h) => h.listId == null && h.owned)
|
|
||||||
.map((h) => ({ id: h.itemId })),
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,9 +173,7 @@ const resolvers = {
|
||||||
userId: id,
|
userId: id,
|
||||||
ownsOrWantsItems: "WANTS",
|
ownsOrWantsItems: "WANTS",
|
||||||
isDefaultList: true,
|
isDefaultList: true,
|
||||||
items: allClosetHangers
|
items: defaultListWantedHangers.map((h) => ({ id: h.itemId })),
|
||||||
.filter((h) => h.listId == null && !h.owned)
|
|
||||||
.map((h) => ({ id: h.itemId })),
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue