Merge pull request #8214 from thornbill/reduce-get-all-apiclients

Reduce calls to getApiClients
This commit is contained in:
Bill Thornton
2026-08-04 16:32:20 -04:00
committed by GitHub
2 changed files with 9 additions and 22 deletions
@@ -33,14 +33,12 @@ EmbyItemRefreshIndicatorPrototype.createdCallback = function () {
const handler = ({ Data }) => onRefreshProgress(this, Data);
this._wsApiClientCreatedHandler = (e, newApiClient) => {
const unsub = newApiClient.subscribe([OutboundWebSocketMessageType.RefreshProgress], handler);
if (unsub) this._wsUnsubscribers.push(unsub);
};
this._wsUnsubscribers = ServerConnections.getApiClients()
.map(apiClient => apiClient.subscribe([OutboundWebSocketMessageType.RefreshProgress], handler))
.filter(Boolean);
const serverId = dom.parentWithAttribute(this, 'data-serverid')?.getAttribute('data-serverid');
const apiClient = serverId ? ServerConnections.getApiClient(serverId) : ServerConnections.currentApiClient();
this._wsUnsubscribers = [];
if (apiClient) {
this._wsUnsubscribers.push(apiClient.subscribe([OutboundWebSocketMessageType.RefreshProgress], handler));
}
};
EmbyItemRefreshIndicatorPrototype.attachedCallback = function () {
@@ -61,10 +59,6 @@ EmbyItemRefreshIndicatorPrototype.detachedCallback = function () {
});
this._wsUnsubscribers = [];
if (this._wsApiClientCreatedHandler) {
this._wsApiClientCreatedHandler = null;
}
this.itemId = null;
};
@@ -72,4 +66,3 @@ document.registerElement('emby-itemrefreshindicator', {
prototype: EmbyItemRefreshIndicatorPrototype,
extends: 'div'
});
@@ -290,19 +290,16 @@ ItemsContainerPrototype.attachedCallback = function () {
itemShortcuts.on(this, getShortcutOptions());
const subscribeToApiClient = (apiClient) => [
const subscribeToApiClient = apiClient => apiClient ? [
apiClient.subscribe([OutboundWebSocketMessageType.UserDataChanged], (msg) => onUserDataChanged(msg, this)),
apiClient.subscribe([OutboundWebSocketMessageType.TimerCreated], (msg) => onTimerCreated(msg, this)),
apiClient.subscribe([OutboundWebSocketMessageType.SeriesTimerCreated], (msg) => onSeriesTimerCreated(msg, this)),
apiClient.subscribe([OutboundWebSocketMessageType.TimerCancelled], (msg) => onTimerCancelled(msg, this)),
apiClient.subscribe([OutboundWebSocketMessageType.SeriesTimerCancelled], (msg) => onSeriesTimerCancelled(msg, this)),
apiClient.subscribe([OutboundWebSocketMessageType.LibraryChanged], (msg) => onLibraryChanged(msg, this))
].filter(Boolean);
].filter(Boolean) : [];
this._wsApiClientCreatedHandler = (e, newApiClient) => {
this._wsUnsubscribers = (this._wsUnsubscribers ?? []).concat(subscribeToApiClient(newApiClient));
};
this._wsUnsubscribers = ServerConnections.getApiClients().flatMap(subscribeToApiClient);
this._wsUnsubscribers = subscribeToApiClient(ServerConnections.currentApiClient());
addNotificationEvent(this, 'playbackstop', onPlaybackStopped, playbackManager);
@@ -326,9 +323,6 @@ ItemsContainerPrototype.detachedCallback = function () {
unsub();
});
this._wsUnsubscribers = [];
if (this._wsApiClientCreatedHandler) {
this._wsApiClientCreatedHandler = null;
}
removeNotificationEvent(this, 'playbackstop', playbackManager);