Skip to content

Commit

Permalink
chore: cache transparency vesting data (#1453)
Browse files Browse the repository at this point in the history
  • Loading branch information
1emu authored Dec 11, 2023
1 parent 5b2e58b commit 134e0be
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/services/ProjectService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logger from 'decentraland-gatsby/dist/entities/Development/logger'

import { DclData } from '../clients/DclData'
import UnpublishedBidModel from '../entities/Bid/model'
import { GrantTier } from '../entities/Grant/GrantTier'
import { GRANT_PROPOSAL_DURATION_IN_SECONDS } from '../entities/Grant/constants'
Expand All @@ -23,11 +22,12 @@ import { createProject } from '../utils/projects'

import { BudgetService } from './BudgetService'
import { ProposalInCreation } from './ProposalService'
import { VestingService } from './VestingService'

export class ProjectService {
public static async getProjects() {
const data = await ProposalModel.getProjectList()
const vestings = await DclData.get().getVestings()
const vestings = await VestingService.getAllVestings()
const projects: ProjectWithUpdate[] = []

await Promise.all(
Expand Down
16 changes: 16 additions & 0 deletions src/services/VestingService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
import { DclData, TransparencyVesting } from '../clients/DclData'
import { VestingInfo, getVestingContractData } from '../clients/VestingData'

import CacheService, { TTL_24_HS } from './CacheService'

export class VestingService {
static async getAllVestings() {
const cacheKey = `vesting-data`

const cachedData = CacheService.get<TransparencyVesting[]>(cacheKey)
if (cachedData) {
return cachedData
}

const transparencyVestings = await DclData.get().getVestings()
CacheService.set(cacheKey, transparencyVestings, TTL_24_HS)
return transparencyVestings
}

static async getVestingInfo(addresses: string[]): Promise<VestingInfo[]> {
const vestings = await Promise.all(addresses.map((address) => getVestingContractData(address)))

Expand Down

0 comments on commit 134e0be

Please sign in to comment.