From 1a30206ad04e627c18f39fd62564aaa3820db503 Mon Sep 17 00:00:00 2001 From: Andrey Mikhadyuk Date: Tue, 21 Nov 2023 15:50:58 +0300 Subject: [PATCH] add ability to fetch all parent commons for common from cache --- src/pages/commonFeed/hooks/useCommonData/index.ts | 2 +- src/services/Common.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pages/commonFeed/hooks/useCommonData/index.ts b/src/pages/commonFeed/hooks/useCommonData/index.ts index fd11a97fcf..018aab6ca8 100644 --- a/src/pages/commonFeed/hooks/useCommonData/index.ts +++ b/src/pages/commonFeed/hooks/useCommonData/index.ts @@ -70,7 +70,7 @@ export const useCommonData = (userId?: string): Return => { const { rootCommonId } = common; const [parentCommons, subCommons, rootCommonGovernance] = await Promise.all([ - CommonService.getAllParentCommonsForCommon(common), + CommonService.getAllParentCommonsForCommon(common, true), CommonService.getCommonsByDirectParentIds([common.id]), rootCommonId ? GovernanceService.getGovernanceByCommonId(rootCommonId) diff --git a/src/services/Common.ts b/src/services/Common.ts index 7d5573ffe4..7415f283de 100644 --- a/src/services/Common.ts +++ b/src/services/Common.ts @@ -17,7 +17,6 @@ import { SubCollections, } from "@/shared/models"; import { - convertObjectDatesToFirestoreTimestamps, emptyFunction, firestoreDataConverter, transformFirebaseDataList, @@ -258,10 +257,11 @@ class CommonService { // Fetch all parent commons. Order: from root parent common to lowest ones public getAllParentCommonsForCommon = async ( commonToCheck: Pick | string, + cached = false, ): Promise => { const common = typeof commonToCheck === "string" - ? await this.getCommonById(commonToCheck) + ? await this.getCommonById(commonToCheck, cached) : commonToCheck; if (!common || common.directParent === null) { @@ -272,7 +272,7 @@ class CommonService { let nextCommonId = common.directParent.commonId; while (nextCommonId) { - const common = await this.getCommonById(nextCommonId); + const common = await this.getCommonById(nextCommonId, cached); if (common) { finalCommons = [common, ...finalCommons];