From d84190f58d2bdc56a1c9c88e9e2cdc718979b0f6 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Thu, 31 Aug 2017 17:49:19 +0100 Subject: [PATCH] Explain Flair debounce --- src/components/views/elements/Flair.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/components/views/elements/Flair.js b/src/components/views/elements/Flair.js index 9b0534e9b0..cd0acd92f8 100644 --- a/src/components/views/elements/Flair.js +++ b/src/components/views/elements/Flair.js @@ -70,6 +70,16 @@ function getPublicGroupsCached(matrixClient, userId) { delete usersPending[userId]; }); + // This debounce will allow consecutive requests for the public groups of users that + // are sent in intervals of < BULK_REQUEST_DEBOUNCE_MS to be batched and only requested + // when no more requests are received within the next BULK_REQUEST_DEBOUNCE_MS. The naive + // implementation would do a request that only requested the groups for `userId`, leading + // to a worst and best case of 1 user per request. This implementation's worst is still + // 1 user per request but only if the requests are > BULK_REQUEST_DEBOUNCE_MS apart and the + // best case is N users per request. + // + // This is to reduce the number of requests made whilst trading off latency when viewing + // a Flair component. if (debounceTimeoutID) clearTimeout(debounceTimeoutID); debounceTimeoutID = setTimeout(() => { batchedGetPublicGroups(matrixClient);