From 7596f8b8fd1a14cbdaf10f1c8a72f7e3912a626c Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> Date: Thu, 29 Jan 2026 16:05:03 -0500 Subject: [PATCH] Batch relay-driven UI refreshes --- js/app.js | 58 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/js/app.js b/js/app.js index e696dccc..a2e54282 100644 --- a/js/app.js +++ b/js/app.js @@ -183,6 +183,7 @@ const UNSUPPORTED_BTITH_MESSAGE = const FALLBACK_THUMBNAIL_SRC = "/assets/jpg/video-thumbnail-fallback.jpg"; const VIDEO_EVENT_KIND = 30078; const HEX64_REGEX = /^[0-9a-f]{64}$/i; +const RELAY_UI_BATCH_DELAY_MS = 250; /** * Simple IntersectionObserver-based lazy loader for images (or videos). * @@ -250,6 +251,7 @@ class Application { this.dmRecipientPubkey = null; this.dmRelayHints = new Map(); this.authLoadingState = { profile: "idle", lists: "idle", dms: "idle" }; + this.relayUiRefreshTimeout = null; this.commentController = null; this.initializeCommentController(); @@ -4576,24 +4578,46 @@ class Application { return; } - if (this.profileController) { - try { - this.profileController.populateProfileRelays(); - } catch (error) { - devLogger.warn( - "[Application] Failed to refresh profile relays after relays loaded:", - error, - ); - } + this.scheduleRelayUiRefresh(); + } - try { - void this.profileController.refreshDmRelayPreferences({ force: true }); - } catch (error) { - devLogger.warn( - "[Application] Failed to refresh DM relay preferences after relays loaded:", - error, - ); - } + scheduleRelayUiRefresh() { + if (this.relayUiRefreshTimeout) { + return; + } + + const scheduleTimeout = + typeof window !== "undefined" && typeof window.setTimeout === "function" + ? window.setTimeout.bind(window) + : setTimeout; + + this.relayUiRefreshTimeout = scheduleTimeout(() => { + this.relayUiRefreshTimeout = null; + this.flushRelayUiRefresh(); + }, RELAY_UI_BATCH_DELAY_MS); + } + + flushRelayUiRefresh() { + if (!this.profileController) { + return; + } + + try { + this.profileController.populateProfileRelays(); + } catch (error) { + devLogger.warn( + "[Application] Failed to refresh profile relays after relays loaded:", + error, + ); + } + + try { + void this.profileController.refreshDmRelayPreferences({ force: true }); + } catch (error) { + devLogger.warn( + "[Application] Failed to refresh DM relay preferences after relays loaded:", + error, + ); } }