Skip to content

Commit

Permalink
remove refresh_project_summary_from totals and add user cache (#1539)
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosQ96 authored May 7, 2024
1 parent 7db0975 commit ab7c5c6
Showing 4 changed files with 51 additions and 20 deletions.
50 changes: 34 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions src/entities/user.ts
Original file line number Diff line number Diff line change
@@ -216,6 +216,10 @@ export class User extends BaseEntity {
status: DONATION_STATUS.VERIFIED,
})
.andWhere(`donation."recurringDonationId" IS NULL`)
.cache(
`user-donationsCount-normal-${this.id}`,
Number(process.env.USER_STATS_CACHE_TIME || 60000),
)
.getCount();

// Count for recurring donations
@@ -224,6 +228,10 @@ export class User extends BaseEntity {
)
.where(`recurring_donation."donorId" = :donorId`, { donorId: this.id })
.andWhere('recurring_donation.totalUsdStreamed > 0')
.cache(
`user-donationsCount-recurring-${this.id}`,
Number(process.env.USER_STATS_CACHE_TIME || 60000),
)
.getCount();

// Sum of both counts
@@ -239,6 +247,10 @@ export class User extends BaseEntity {
`project.statusId = ${ProjStatus.active} AND project.reviewStatus = :reviewStatus`,
{ reviewStatus: ReviewStatus.Listed },
)
.cache(
`user-likedProjectsCount-recurring-${this.id}`,
Number(process.env.USER_STATS_CACHE_TIME || 60000),
)
.getCount();

return likedProjectsCount;
6 changes: 5 additions & 1 deletion src/repositories/powerBoostingRepository.ts
Original file line number Diff line number Diff line change
@@ -165,7 +165,11 @@ export const findPowerBoostingsCountByUserId = async (
.leftJoin('powerBoosting.user', 'user')
.addSelect(publicSelectionFields)
.where(`percentage > 0`)
.andWhere(`"userId" =${userId}`);
.andWhere(`"userId" =${userId}`)
.cache(
`findPowerBoostingsCountByUserId-recurring-${userId}`,
Number(process.env.USER_STATS_CACHE_TIME || 60000),
);
return query.getCount();
};

3 changes: 0 additions & 3 deletions src/services/donationService.ts
Original file line number Diff line number Diff line change
@@ -198,9 +198,6 @@ export const updateTotalDonationsOfProject = async (
`,
[projectId],
);

// we want to update the project donation summary view after updating the total donations
refreshProjectDonationSummaryView();
} catch (e) {
logger.error('updateTotalDonationsOfAProject error', e);
}

0 comments on commit ab7c5c6

Please sign in to comment.