From bba31c17af9fa5ba0df5f403999b65281072981a Mon Sep 17 00:00:00 2001 From: Shubham Parihar Date: Fri, 24 Sep 2021 20:40:58 +0530 Subject: [PATCH 1/2] fix(CachedManager): return updated data when cache is false --- src/managers/CachedManager.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/managers/CachedManager.js b/src/managers/CachedManager.js index f532db68ef25..194ad7b25f39 100644 --- a/src/managers/CachedManager.js +++ b/src/managers/CachedManager.js @@ -45,8 +45,10 @@ class CachedManager extends DataManager { _add(data, cache = true, { id, extras = [] } = {}) { const existing = this.cache.get(id ?? data.id); - if (cache) existing?._patch(data); - if (existing) return existing; + if (existing) { + if (cache) return existing._patch(data); + return existing._clone()._patch(data); + } const entry = this.holds ? new this.holds(this.client, data, ...extras) : data; if (cache) this.cache.set(id ?? entry.id, entry); From 679db829ccfc723a48bb4308a2cc7e3a6d0b6e14 Mon Sep 17 00:00:00 2001 From: Shubham Parihar Date: Fri, 24 Sep 2021 21:14:22 +0530 Subject: [PATCH 2/2] fix(CachedManager): return the structure correctly --- src/managers/CachedManager.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/managers/CachedManager.js b/src/managers/CachedManager.js index 194ad7b25f39..0f7e914077e4 100644 --- a/src/managers/CachedManager.js +++ b/src/managers/CachedManager.js @@ -46,8 +46,13 @@ class CachedManager extends DataManager { _add(data, cache = true, { id, extras = [] } = {}) { const existing = this.cache.get(id ?? data.id); if (existing) { - if (cache) return existing._patch(data); - return existing._clone()._patch(data); + if (cache) { + existing._patch(data); + return existing; + } + const clone = existing._clone(); + clone._patch(data); + return clone; } const entry = this.holds ? new this.holds(this.client, data, ...extras) : data;