From 602dc4f721a9a7f08782a475a69fdade08d0aa8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hanno=20J=2E=20G=C3=B6decke?= Date: Thu, 24 Aug 2023 08:25:44 +0200 Subject: [PATCH 1/3] optimize getDefaultAvatar calculation --- src/libs/UserUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/UserUtils.js b/src/libs/UserUtils.js index dffb5580f0d3..5d465d56349f 100644 --- a/src/libs/UserUtils.js +++ b/src/libs/UserUtils.js @@ -89,7 +89,7 @@ function getDefaultAvatar(accountID = -1) { // There are 24 possible default avatars, so we choose which one this user has based // on a simple hash of their login. Note that Avatar count starts at 1. - const accountIDHashBucket = hashText(accountID.toString(), CONST.DEFAULT_AVATAR_COUNT) + 1; + const accountIDHashBucket = (accountID % 24) + 1; return defaultAvatars[`Avatar${accountIDHashBucket}`]; } From 297ebbee76bea2028baac9d4aa1f58765f6113d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hanno=20J=2E=20G=C3=B6decke?= Date: Thu, 24 Aug 2023 08:58:03 +0200 Subject: [PATCH 2/3] use const --- src/libs/UserUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/UserUtils.js b/src/libs/UserUtils.js index 5d465d56349f..e1bc615a96b1 100644 --- a/src/libs/UserUtils.js +++ b/src/libs/UserUtils.js @@ -89,7 +89,7 @@ function getDefaultAvatar(accountID = -1) { // There are 24 possible default avatars, so we choose which one this user has based // on a simple hash of their login. Note that Avatar count starts at 1. - const accountIDHashBucket = (accountID % 24) + 1; + const accountIDHashBucket = (accountID % CONST.DEFAULT_AVATAR_COUNT) + 1; return defaultAvatars[`Avatar${accountIDHashBucket}`]; } From bd1dafc9ded2b30148415bf7728e30af94674bb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hanno=20J=2E=20G=C3=B6decke?= Date: Thu, 24 Aug 2023 12:22:29 +0200 Subject: [PATCH 3/3] update comment --- src/libs/UserUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/UserUtils.js b/src/libs/UserUtils.js index e1bc615a96b1..918c2c9bbdc6 100644 --- a/src/libs/UserUtils.js +++ b/src/libs/UserUtils.js @@ -88,7 +88,7 @@ function getDefaultAvatar(accountID = -1) { } // There are 24 possible default avatars, so we choose which one this user has based - // on a simple hash of their login. Note that Avatar count starts at 1. + // on a simple modulo operation of their login number. Note that Avatar count starts at 1. const accountIDHashBucket = (accountID % CONST.DEFAULT_AVATAR_COUNT) + 1; return defaultAvatars[`Avatar${accountIDHashBucket}`];