Skip to content

Commit

Permalink
Clear cache
Browse files Browse the repository at this point in the history
  • Loading branch information
ef1rspb authored Aug 19, 2021
1 parent 3f7958b commit dfcdb65
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/mappings/StakeChanged.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export async function handleSlashForAnalytics(event: SubstrateEvent): Promise<vo
await element.save()
}

// Due to memory consumption optimization `rewardDestinationByAddress` contains only one key
let rewardDestinationByAddress: {[blockId: string]: {[address: string]: RewardDestination}} = {}

async function cachedRewardDestination(accountAddress: string, event: SubstrateEvent): Promise<RewardDestination> {
Expand All @@ -64,6 +65,7 @@ async function cachedRewardDestination(accountAddress: string, event: SubstrateE
if (cachedBlock !== undefined) {
return cachedBlock[accountAddress]
} else {
rewardDestinationByAddress = {}
const allAccountsInBlock = event.block.events
.filter(event => {
return event.event.method == "Reward" && event.event.section == "staking"
Expand Down
2 changes: 2 additions & 0 deletions src/mappings/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,15 @@ export async function cachedCurrentEra(block: SubstrateBlock): Promise<EraIndex>
}
}

// Due to memory consumption optimization `eraStakersByEra` contains only one key
let eraStakersByEra: {[era: number]: [StorageKey<[EraIndex, AccountId]>, Exposure][]} = {}

export async function cachedEraStakers(era: number): Promise<[StorageKey<[EraIndex, AccountId]>, Exposure][]> {
let cachedValue = eraStakersByEra[era]
if (cachedValue !== undefined) {
return cachedValue
} else {
eraStakersByEra = {}
let eraStakers = await api.query.staking.erasStakers.entries(era);
eraStakersByEra[era] = eraStakers
return eraStakers
Expand Down

0 comments on commit dfcdb65

Please sign in to comment.