Skip to content

Commit

Permalink
optimized fetch all
Browse files Browse the repository at this point in the history
  • Loading branch information
froid1911 committed Nov 18, 2021
1 parent c2641c6 commit 7a74602
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 42 deletions.
5 changes: 0 additions & 5 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,3 @@ type Aavegotchi @entity {
right: String
back: String
}

type Stat @entity {
id: ID!
gotchiIds: [BigInt!]!
}
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BigInt } from "@graphprotocol/graph-ts";


export let BLOCK_SIDEVIEWS_ACTIVATED = BigInt.fromI32(20000000);
export let BLOCK_SIDEVIEWS_ACTIVATED = BigInt.fromI32(21420703);
23 changes: 1 addition & 22 deletions src/helper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Address, BigInt } from "@graphprotocol/graph-ts";
import { Contract } from "../generated/Contract/Contract";
import { Aavegotchi, Stat } from "../generated/schema";
import { Aavegotchi } from "../generated/schema";

export function updateSvg(gotchi: BigInt): Aavegotchi | null {
let contract = Contract.bind(Address.fromString("0x86935F11C86623deC8a25696E1C19a8659CbF95d"))
Expand Down Expand Up @@ -38,24 +38,3 @@ export function getOrCreateAavegotchi(gotchi: BigInt): Aavegotchi {

return gotchiEntity as Aavegotchi;
}

export function updateStats(gotchi: BigInt): Stat | null {
let stats = Stat.load("0");
if(!stats) {
stats = new Stat("0");
stats.gotchiIds = new Array<BigInt>();
}

let gotchiIds = stats.gotchiIds;

for(let i=0; i<gotchiIds.length; i++) {
let gotchiId = gotchiIds[i];
if(gotchiId == gotchi) {
return null;
}
}

gotchiIds.push(gotchi);
stats.gotchiIds = gotchiIds;
return stats;
}
16 changes: 3 additions & 13 deletions src/mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,14 @@ import {
WearableSlotPositionsSet,
MintPortals
} from "../generated/Contract/Contract"
import { Stat } from "../generated/schema";
import { BLOCK_SIDEVIEWS_ACTIVATED } from "./constants";
import { updateSideViews, updateStats, updateSvg } from "./helper"
import { getOrCreateAavegotchi, updateSideViews, updateSvg } from "./helper"

export function handleClaimAavegotchi(event: ClaimAavegotchi): void {
let gotchi = event.block.number.ge(BLOCK_SIDEVIEWS_ACTIVATED) ? updateSideViews(event.params._tokenId) : updateSvg(event.params._tokenId);
if(gotchi != null) {
gotchi.save();
}

let stats = updateStats(event.params._tokenId);
if(stats != null) {
stats.save();
}
}

export function handleLockAavegotchi(event: LockAavegotchi): void {}
Expand Down Expand Up @@ -251,14 +245,10 @@ export function handleBlock(block: ethereum.Block): void {
}

// update side views
let stats = Stat.load("0")!;
let gotchiIds = stats.gotchiIds;
let i=0;
while(i < gotchiIds.length) {
let gotchi = updateSideViews(gotchiIds[i]);
for(let i=0; i<=25000; i++) {
let gotchi = updateSideViews(BigInt.fromI32(i));
if(gotchi != null) {
gotchi.save();
}
i = i+1;
}
}
2 changes: 1 addition & 1 deletion subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dataSources:
source:
address: "0x86935F11C86623deC8a25696E1C19a8659CbF95d"
abi: Contract
startBlock: 11500000
startBlock: 21320703
mapping:
kind: ethereum/events
apiVersion: 0.0.5
Expand Down

0 comments on commit 7a74602

Please sign in to comment.