git » sdk » commit 697d0e3

Do not load participants when we aren't going to use them

author Stephen Paul Weber
2025-06-24 17:48:05 UTC
committer Stephen Paul Weber
2025-06-24 17:48:05 UTC
parent 1f4fa9262a33530298f1702854e71fce8c08e6a4

Do not load participants when we aren't going to use them

Profiling showed it can be expensive

snikket/Chat.hx +12 -9

diff --git a/snikket/Chat.hx b/snikket/Chat.hx
index 2ddb330..bd552ef 100644
--- a/snikket/Chat.hx
+++ b/snikket/Chat.hx
@@ -469,16 +469,19 @@ abstract class Chat {
 		The display name of this Chat
 	**/
 	public function getDisplayName() {
-		final fn = this.displayName == chatId && chatId == client.accountId() ? client.displayName() : this.displayName;
-		final participants = getParticipants();
-		if (fn == chatId && participants.length > 2 && participants.length < 20) {
-			return participants.map(id -> {
-				final p = getParticipantDetails(id);
-				p.isSelf ? null : p.displayName;
-			}).filter(fn -> fn != null).join(", ");
-		} else {
-			return fn;
+		if (this.displayName == chatId) {
+			if (chatId == client.accountId()) return client.displayName();
+
+			final participants = getParticipants();
+			if (participants.length > 2 && participants.length < 20) {
+				return participants.map(id -> {
+					final p = getParticipantDetails(id);
+					p.isSelf ? null : p.displayName;
+				}).filter(fn -> fn != null).join(", ");
+			}
 		}
+
+		return this.displayName;
 	}
 
 	@:allow(snikket)