Skip to content

Commit

Permalink
add ability to fetch all parent commons for common from cache
Browse files Browse the repository at this point in the history
  • Loading branch information
andreymikhadyuk committed Nov 21, 2023
1 parent e3531fd commit 1a30206
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/pages/commonFeed/hooks/useCommonData/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/services/Common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
SubCollections,
} from "@/shared/models";
import {
convertObjectDatesToFirestoreTimestamps,
emptyFunction,
firestoreDataConverter,
transformFirebaseDataList,
Expand Down Expand Up @@ -258,10 +257,11 @@ class CommonService {
// Fetch all parent commons. Order: from root parent common to lowest ones
public getAllParentCommonsForCommon = async (
commonToCheck: Pick<Common, "directParent"> | string,
cached = false,
): Promise<Common[]> => {
const common =
typeof commonToCheck === "string"
? await this.getCommonById(commonToCheck)
? await this.getCommonById(commonToCheck, cached)
: commonToCheck;

if (!common || common.directParent === null) {
Expand All @@ -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];
Expand Down

0 comments on commit 1a30206

Please sign in to comment.