From 28f5b4dee88dae40cea71241eab2cf0044503fc4 Mon Sep 17 00:00:00 2001 From: Kev Date: Mon, 18 Nov 2024 01:08:11 +0100 Subject: [PATCH] Speed up didToProfile in large queues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This speeds up the `didToProfile` helper on the queue page if the queue is large (say over 500 accounts). I’m not quite sure why the current solution is this slow (up to 3s to rerender) since we should only be looking at 2.25 million lookups maxium in a queue of n = 1500. Generating the map initially takes around 2ms and any lookups via `didToProfile` go down from around 40ms to <0.2ms. --- web/admin/pages/index.vue | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/web/admin/pages/index.vue b/web/admin/pages/index.vue index 0744dc56..08144f1f 100644 --- a/web/admin/pages/index.vue +++ b/web/admin/pages/index.vue @@ -15,6 +15,16 @@ const currentQueue = ref("All"); const error = ref(); +const actorProfilesMap = computed(() => { + const map = new Map(); + + for (const profile of actorProfiles.value) { + map.set(profile.did, profile); + } + + return map; +}); + const queues = computed(() => ({ All: actors.value, "Probably furry": actors.value.filter((actor) => { @@ -59,7 +69,7 @@ const nextActor = async () => { await nextActor(); function didToProfile(did: string): ProfileViewDetailed | undefined { - return actorProfiles.value.find((p) => p.did === did); + return actorProfilesMap.value.get(did); } function selectRandomActor() {