mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
Merge pull request #1951 from PR0M3TH3AN/codex/add-batching-and-debouncing-for-relay-events
Batch relay-driven UI refreshes
This commit is contained in:
1 file changed
+41
-17
@@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user