From e4818d2532b5cf12456a963a2d0d26cc2d02f445 Mon Sep 17 00:00:00 2001 From: Jesse Chan Date: Sun, 2 May 2021 00:30:23 +0800 Subject: [PATCH] server: qBittorrent: always fetch full peer list (reverts 7846eb6) Sync API does not bring much benefits for mostly localhost transfers. --- .../qBittorrent/clientRequestManager.ts | 55 +++---------------- 1 file changed, 9 insertions(+), 46 deletions(-) diff --git a/server/services/qBittorrent/clientRequestManager.ts b/server/services/qBittorrent/clientRequestManager.ts index 335fee9b..c1b9d7a6 100644 --- a/server/services/qBittorrent/clientRequestManager.ts +++ b/server/services/qBittorrent/clientRequestManager.ts @@ -39,15 +39,12 @@ class ClientRequestManager { private syncRids: { mainData: Promise; - torrentPeers: Record>; } = { mainData: Promise.resolve(0), - torrentPeers: {}, }; private syncStates: { mainData: QBittorrentMainData; - torrentPeers: Record; } = { mainData: { categories: {}, @@ -56,7 +53,6 @@ class ClientRequestManager { torrents: {}, trackers: {}, }, - torrentPeers: {}, }; async authenticate(connectionSettings = this.connectionSettings): Promise { @@ -266,48 +262,15 @@ class ClientRequestManager { } async syncTorrentPeers(hash: string): Promise { - const Cookie = await this.authCookie; - - this.syncRids.torrentPeers[hash] = (this.syncRids.torrentPeers[hash] ?? Promise.resolve(0)).then((rid) => - axios - .get(`${this.apiBase}/sync/torrentPeers`, { - params: { - hash, - rid, - }, - headers: {Cookie}, - }) - .then(({data}) => { - const {peers = {}, peers_removed = [], rid: newRid = 0} = data; - - if (this.syncStates.torrentPeers[hash] == null) { - this.syncStates.torrentPeers[hash] = {}; - } - - Object.keys(peers).forEach((ip_and_port) => { - this.syncStates.torrentPeers[hash][ip_and_port] = { - ...this.syncStates.torrentPeers[hash][ip_and_port], - ...peers[ip_and_port], - }; - }); - - peers_removed.forEach((ip_and_port) => { - delete this.syncStates.torrentPeers[hash][ip_and_port]; - }); - - return newRid; - }), - ); - - try { - await this.syncRids.torrentPeers[hash]; - } catch (e) { - delete this.syncRids.torrentPeers[hash]; - delete this.syncStates.torrentPeers[hash]; - throw e; - } - - return this.syncStates.torrentPeers[hash]; + return axios + .get(`${this.apiBase}/sync/torrentPeers`, { + params: { + hash, + rid: 0, + }, + headers: {Cookie: await this.authCookie}, + }) + .then(({data}) => data.peers as QBittorrentTorrentPeers); } async torrentsPause(hashes: Array): Promise {