Skip to content

Commit

Permalink
fix: dont use Equal for updating values
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanVerstraete committed Jan 24, 2023
1 parent f71488b commit fe7c94b
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion indexer/chart/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ name: tfchainindexer
description: Helm Chart for the tfchain hydra indexer
version: 2.7.6
apiVersion: v2
appVersion: '2.8.0-rc6'
appVersion: '2.8.0-rc7'
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "graphql_tfgrid",
"private": "true",
"version": "2.8.0-rc6",
"version": "2.8.0-rc7",
"description": "GraphQL server and Substrate indexer. Generated with ♥ by Hydra-CLI",
"author": "",
"license": "ISC",
Expand Down Expand Up @@ -41,4 +41,4 @@
"@types/node": "16.11.47",
"typescript": "4.7.4"
}
}
}
2 changes: 1 addition & 1 deletion processor-chart/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ apiVersion: v2
name: tfchain-processor
description: A chart for the tfchain graphql processor and query node
version: 1.0.5
appVersion: '2.8.0-rc6'
appVersion: '2.8.0-rc7'
3 changes: 1 addition & 2 deletions src/mappings/contracts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Store } from '@subsquid/typeorm-store'
import { Equal } from 'typeorm';
import { Ctx } from '../processor'
import { EventItem } from '@subsquid/substrate-processor/lib/interfaces/dataSelection'

Expand Down Expand Up @@ -377,7 +376,7 @@ export async function contractUpdateUsedResources(
const savedContract = await ctx.store.get(NodeContract, { where: { contractID: usedResources.contractId } })
if (!savedContract) return

const savedContractResources = await ctx.store.get(ContractResources, { where: { contract: Equal(savedContract) }, relations: { contract: true } })
const savedContractResources = await ctx.store.get(ContractResources, { where: { contract: { contractID: savedContract.contractID } }, relations: { contract: true } })
if (savedContractResources) {
savedContractResources.cru = usedResources.used.cru
savedContractResources.sru = usedResources.used.sru
Expand Down
18 changes: 8 additions & 10 deletions src/mappings/nodes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Node, Location, PublicConfig, NodeCertification, Interfaces, UptimeEvent, NodeResourcesTotal } from "../model";
import { TfgridModuleNodeCertificationSetEvent, TfgridModuleNodeDeletedEvent, TfgridModuleNodePublicConfigStoredEvent, TfgridModuleNodeStoredEvent, TfgridModuleNodeUpdatedEvent, TfgridModuleNodeUptimeReportedEvent } from "../types/events";
import { Equal } from 'typeorm';
import { SubstrateBlock } from '@subsquid/substrate-processor';
import { In } from 'typeorm'
import { EventItem } from '@subsquid/substrate-processor/lib/interfaces/dataSelection'
Expand Down Expand Up @@ -126,7 +125,6 @@ export async function nodeStored(
resourcesTotal.hru = nodeEvent.resources.hru
resourcesTotal.mru = nodeEvent.resources.mru
resourcesTotal.cru = nodeEvent.resources.cru

await ctx.store.save<NodeResourcesTotal>(resourcesTotal)

newNode.interfaces = []
Expand Down Expand Up @@ -184,7 +182,7 @@ export async function nodeUpdated(
savedNode.farmingPolicyId = nodeEvent.farmingPolicyId

// Recalculate total / free resoures when a node get's updated
let resourcesTotal = await ctx.store.get(NodeResourcesTotal, { where: { node: Equal(savedNode) }, relations: { node: true } })
let resourcesTotal = await ctx.store.get(NodeResourcesTotal, { where: { node: { nodeID: savedNode.nodeID } }, relations: { node: true } })
if (resourcesTotal) {
resourcesTotal.sru = nodeEvent.resources.sru
resourcesTotal.hru = nodeEvent.resources.hru
Expand Down Expand Up @@ -353,21 +351,21 @@ export async function nodeDeleted(
) {
const nodeID = new TfgridModuleNodeDeletedEvent(ctx, item.event).asV49

const savedNode = await ctx.store.get(Node, { where: { nodeID: nodeID }, relations: { location: true } })
const savedNode = await ctx.store.get(Node, { where: { nodeID: nodeID }, relations: { location: true, interfaces: true } })

if (savedNode) {
const resourcesTotal = await ctx.store.find(NodeResourcesTotal, { where: { node: Equal(savedNode) }, relations: { node: true } })
const resourcesTotal = await ctx.store.find(NodeResourcesTotal, { where: { node: { nodeID: savedNode.nodeID } }, relations: { node: true } })
if (resourcesTotal) {
const p = resourcesTotal.map(r => ctx.store.remove(r))
await Promise.all(p)
}

const pubConfig = await ctx.store.get(PublicConfig, { where: { node: Equal(savedNode) }, relations: { node: true } })
const pubConfig = await ctx.store.get(PublicConfig, { where: { node: { nodeID: savedNode.nodeID } }, relations: { node: true } })
if (pubConfig) {
await ctx.store.remove(pubConfig)
}

const intfs = await ctx.store.find(Interfaces, { where: { node: Equal(savedNode) }, relations: { node: true } })
const intfs = await ctx.store.find(Interfaces, { where: { node: { nodeID: savedNode.nodeID } }, relations: { node: true } })
const promises = intfs.map(intf => {
return ctx.store.remove(intf)
})
Expand Down Expand Up @@ -449,10 +447,10 @@ export async function nodePublicConfigStored(
return
}

const savedNode = await ctx.store.get(Node, { where: { nodeID: nodeID }, relations: { location: true } })
const savedNode = await ctx.store.get(Node, { where: { nodeID: nodeID }, relations: { location: true, interfaces: true } })
if (!savedNode) return

let publicConfig = await ctx.store.get(PublicConfig, { where: { node: Equal(savedNode) }, relations: { node: true } })
let publicConfig = await ctx.store.get(PublicConfig, { where: { node: { nodeID: savedNode.nodeID } }, relations: { node: true } })

if (!publicConfig) {
publicConfig = new PublicConfig()
Expand All @@ -475,7 +473,7 @@ export async function nodeCertificationSet(
) {
const [nodeID, certification] = new TfgridModuleNodeCertificationSetEvent(ctx, item.event).asV63

const savedNode = await ctx.store.get(Node, { where: { nodeID: nodeID }, relations: { location: true } })
const savedNode = await ctx.store.get(Node, { where: { nodeID: nodeID }, relations: { location: true, interfaces: true } })
if (!savedNode) return

let certType = NodeCertification.Diy
Expand Down

0 comments on commit fe7c94b

Please sign in to comment.