Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
fix(good-ghosting): Cache games API data for 15m to prevent 502 error…
Browse files Browse the repository at this point in the history
…s when trashing the endpoint
  • Loading branch information
immasandwich committed Jun 4, 2022
1 parent ea2a67f commit a075d9c
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,28 @@ import { Injectable } from '@nestjs/common';
import axios from 'axios';

import { SingleStakingFarmDefinition } from '~app-toolkit';
import { CacheOnInterval } from '~cache/cache-on-interval.decorator';
import { Network } from '~types';

import GOOD_GHOSTING_DEFINITION from '../good-ghosting.definition';

import { GamesResponse } from './constants';

@Injectable()
export class GoodGhostingGameConfigFetcherHelper {
async getGameConfigs(networkIdParam: string) {
@CacheOnInterval({
key: `studio:${GOOD_GHOSTING_DEFINITION.id}:${GOOD_GHOSTING_DEFINITION.groups.game}:${Network.POLYGON_MAINNET}:addresses`,
timeout: 15 * 60 * 1000,
})
async getCachedGameConfigsData() {
const url = `https://goodghosting-api.com/v1/games`;

const response = await axios.get<GamesResponse>(url);
const gameConfigs = response.data;
const farms: (SingleStakingFarmDefinition & { contractVersion: string })[] = [];
return response.data;
}

async getGameConfigs(networkIdParam: string) {
const farms: (SingleStakingFarmDefinition & { contractVersion: string })[] = [];
const gameConfigs = await this.getCachedGameConfigsData();
const gameContractAddresses = Object.keys(gameConfigs);

for (let i = 0; i < gameContractAddresses.length; i += 1) {
Expand Down

0 comments on commit a075d9c

Please sign in to comment.