Skip to content

Commit f5391a0

Browse files
authored
feat: Derive parcels in estate for performance (#837)
* feat: Derive parcels in estate for performance * feat: Remove parcels settup in buildEstateFromNFT * feat: Update how size and searchEstateSize are assigned * chore: Add temp to readme * chore: Update hashes in readme * chore: Update goerli hashes with new deployment * chore: Move temp under goerli * chore: Add temp to deploy and package json * chore: Update temp hashes with new deploy * chore: Update hashes
1 parent f70365e commit f5391a0

File tree

6 files changed

+22
-23
lines changed

6 files changed

+22
-23
lines changed

indexer/README.md

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
# Blockchain indexer
22

3-
- Mainnet: https://thegraph.com/hosted-service/subgraph/decentraland/marketplace (QmWF9uXD9KokRU1hA5Gnmc3VKU5mPU3cAYmD15cfa8YDTT)
4-
- Ropsten: https://thegraph.com/hosted-service/subgraph/decentraland/marketplace-ropsten (QmfHCGhLTZV8v2duxDkKtPZKMEdJM7X8YGRj2UvqmrAUBB)
3+
- Mainnet: https://thegraph.com/hosted-service/subgraph/decentraland/marketplace
4+
- Prev: `QmYXc2SCC85dvd3pL6yYfxCkLuaCvJaiES3pA4inGiGwej`
5+
- Curr: `QmccAwofKfT9t4XKieDqwZre1UUZxuHw5ynB35BHwHAJDT`
6+
- Ropsten: https://thegraph.com/hosted-service/subgraph/decentraland/marketplace-ropsten
7+
- Prev: `QmfHCGhLTZV8v2duxDkKtPZKMEdJM7X8YGRj2UvqmrAUBB`
8+
- Curr: `QmZTADndoP4XRoWGVoQuaz8WTATx3UDXMn5SdE3GfkErkW`
59
- Goerli: https://thegraph.com/hosted-service/subgraph/decentraland/marketplace-goerli
6-
- Prev: `QmVJ5XudhdALBoyYg8w4bPC62E2N6LKgDteVA2NFnETsL2`
7-
- Curr: `QmRNcz6TmfrFSYZcChetAiivCktGnEpAMrdRYFg74Sm9CU`
10+
- Prev: `QmRNcz6TmfrFSYZcChetAiivCktGnEpAMrdRYFg74Sm9CU`
11+
- Curr: `Qmds1Ut7L2Kvr5Y4ZnCvpMaomcQvhq7BpjhVPgxP5TEfhT`
12+
- Temp: https://thegraph.com/hosted-service/subgraph/decentraland/marketplace-temp
13+
- Prev: `QmccAwofKfT9t4XKieDqwZre1UUZxuHw5ynB35BHwHAJDT`
14+
- Curr: `QmYXc2SCC85dvd3pL6yYfxCkLuaCvJaiES3pA4inGiGwej`
815

916
It uses [thegraph](https://thegraph.com)
1017

indexer/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"deploy-studio:mainnet": "graph deploy --node https://api.studio.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ decentraland-marketplace-ethereum-mainnet",
1212
"deploy:ropsten": "ts-node ./scripts/buildData.ts --network ropsten && ts-node ./scripts/deploy.ts --network ropsten",
1313
"deploy:mainnet": "ts-node ./scripts/buildData.ts --network mainnet && ts-node ./scripts/deploy.ts --network mainnet",
14-
"deploy:goerli": "ts-node ./scripts/buildData.ts --network goerli && ts-node ./scripts/deploy.ts --network goerli"
14+
"deploy:goerli": "ts-node ./scripts/buildData.ts --network goerli && ts-node ./scripts/deploy.ts --network goerli",
15+
"deploy:temp": "ts-node ./scripts/buildData.ts --network mainnet && ts-node ./scripts/deploy.ts --network temp"
1516
},
1617
"devDependencies": {
1718
"@graphprotocol/graph-cli": "^0.21.1",

indexer/schema.graphql

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ type Estate @entity {
9191
id: ID!
9292
tokenId: BigInt!
9393
owner: Account!
94-
parcels: [Parcel!]
94+
parcels: [Parcel!]! @derivedFrom(field: "estate")
9595
size: Int
9696
data: Data
9797
rawData: String

indexer/scripts/deploy.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ import { spawn, SpawnOptions } from 'child_process'
33
enum Network {
44
MAINNET = 'mainnet',
55
ROPSTEN = 'ropsten',
6-
GOERLI = 'goerli'
6+
GOERLI = 'goerli',
7+
TEMP = 'temp'
78
}
89

910
const graphByNetwork: Record<Network, string> = {
1011
[Network.MAINNET]: process.env.GRAPH_NAME || 'decentraland/marketplace',
1112
[Network.ROPSTEN]: process.env.GRAPH_NAME || 'decentraland/marketplace-ropsten',
12-
[Network.GOERLI]: process.env.GRAPH_NAME || 'decentraland/marketplace-goerli'
13+
[Network.GOERLI]: process.env.GRAPH_NAME || 'decentraland/marketplace-goerli',
14+
[Network.TEMP]: process.env.GRAPH_NAME || 'decentraland/marketplace-temp'
1315
}
1416

1517
// TODO: Handle ctrl+C

indexer/src/handlers/estate.ts

+4-14
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export function handleCreateEstate(event: CreateEstate): void {
2525
estate.tokenId = event.params._estateId
2626
estate.owner = event.params._owner.toHex()
2727
estate.rawData = data
28-
estate.parcels = []
2928
estate.size = 0
3029

3130
let estateData = buildData(id, data, DataType.ESTATE)
@@ -58,16 +57,12 @@ export function handleAddLand(event: AddLand): void {
5857

5958
let estate = Estate.load(id)
6059

61-
let parcels = estate.parcels
62-
parcels.push(parcelId)
63-
64-
estate.parcels = parcels
65-
estate.size = parcels.length
60+
estate.size += 1
6661

6762
estate.save()
6863

6964
let estateNFT = NFT.load(id)
70-
estateNFT.searchEstateSize = parcels.length
65+
estateNFT.searchEstateSize = estate.size
7166
estateNFT.save()
7267

7368
let parcel = Parcel.load(parcelId)
@@ -101,17 +96,12 @@ export function handleRemoveLand(event: RemoveLand): void {
10196

10297
let estate = Estate.load(id)
10398

104-
let parcels = estate.parcels
105-
let index = parcels.indexOf(parcelId)
106-
parcels.splice(index, 1)
107-
108-
estate.parcels = parcels
109-
estate.size = parcels.length
99+
estate.size -= 1
110100

111101
estate.save()
112102

113103
let estateNFT = NFT.load(id)
114-
estateNFT.searchEstateSize = parcels.length
104+
estateNFT.searchEstateSize = estate.size
115105
estateNFT.save()
116106

117107
let parcel = Parcel.load(parcelId)

indexer/src/modules/estate/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ export function buildEstateFromNFT(nft: NFT): Estate {
55

66
estate.tokenId = nft.tokenId
77
estate.owner = nft.owner
8-
estate.parcels = []
98
estate.size = 0
109

1110
return estate

0 commit comments

Comments
 (0)