Skip to content

Commit

Permalink
core: refactor build_filter
Browse files Browse the repository at this point in the history
  • Loading branch information
incrypto32 committed Nov 6, 2023
1 parent 22c3d43 commit 08855f1
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 50 deletions.
53 changes: 26 additions & 27 deletions core/src/subgraph/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,42 +119,41 @@ where
None => true,
};

// if static_filters is not enabled we just stick to the filter based on all the data sources.
if !static_filters {
return C::TriggerFilter::from_data_sources(
self.ctx
.instance()
.hosts()
.iter()
.filter_map(|h| h.data_source().as_onchain())
// Filter out data sources that have reached their end block if the block is final.
.filter(end_block_filter),
);
}

// if static_filters is enabled, build a minimal filter with the static data sources and
// add the necessary filters based on templates.
// if not enabled we just stick to the filter based on all the data sources.
// This specifically removes dynamic data sources based filters because these can be derived
// from templates AND this reduces the cost of egress traffic by making the payloads smaller.
let filter = if static_filters {
if !self.inputs.static_filters {
info!(self.logger, "forcing subgraph to use static filters.")
}

let data_sources = self.ctx.instance().data_sources.clone();
if !self.inputs.static_filters {
info!(self.logger, "forcing subgraph to use static filters.")
}

let mut filter = C::TriggerFilter::from_data_sources(
data_sources
.iter()
.filter_map(|ds| ds.as_onchain())
// Filter out data sources that have reached their end block if the block is final.
.filter(end_block_filter),
);
let data_sources = self.ctx.instance().data_sources.clone();

let templates = self.ctx.instance().templates.clone();
let mut filter = C::TriggerFilter::from_data_sources(
data_sources
.iter()
.filter_map(|ds| ds.as_onchain())
// Filter out data sources that have reached their end block if the block is final.
.filter(end_block_filter),
);

filter.extend_with_template(templates.iter().filter_map(|ds| ds.as_onchain()).cloned());
let templates = self.ctx.instance().templates.clone();

filter
} else {
C::TriggerFilter::from_data_sources(
self.ctx
.instance()
.hosts()
.iter()
.filter_map(|h| h.data_source().as_onchain())
// Filter out data sources that have reached their end block if the block is final.
.filter(end_block_filter),
)
};
filter.extend_with_template(templates.iter().filter_map(|ds| ds.as_onchain()).cloned());

filter
}
Expand Down
23 changes: 0 additions & 23 deletions tests/runner-tests/api-version/subgraph.yaml

This file was deleted.

32 changes: 32 additions & 0 deletions tests/runner-tests/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,38 @@
which "2.0.2"
yaml "1.10.2"

"@graphprotocol/graph-cli@0.54.0-alpha-20230727052453-1e0e6e5":
version "0.54.0-alpha-20230727052453-1e0e6e5"
resolved "https://registry.yarnpkg.com/@graphprotocol/graph-cli/-/graph-cli-0.54.0-alpha-20230727052453-1e0e6e5.tgz#7c36225484d503ab410ea03861d701dc30bc8b1e"
integrity sha512-pxZAJvUXHRMtPIoMTSvVyIjqrfMGCtaqWG9qdRDrLMxUKrIuGWniMKntxaFnHPlgz6OQznN9Zt8wV6uScD/4Sg==
dependencies:
"@float-capital/float-subgraph-uncrashable" "^0.0.0-alpha.4"
"@oclif/core" "2.8.6"
"@whatwg-node/fetch" "^0.8.4"
assemblyscript "0.19.23"
binary-install-raw "0.0.13"
chalk "3.0.0"
chokidar "3.5.3"
debug "4.3.4"
docker-compose "0.23.19"
dockerode "2.5.8"
fs-extra "9.1.0"
glob "9.3.5"
gluegun "5.1.2"
graphql "15.5.0"
immutable "4.2.1"
ipfs-http-client "55.0.0"
jayson "4.0.0"
js-yaml "3.14.1"
prettier "1.19.1"
request "2.88.2"
semver "7.4.0"
sync-request "6.1.0"
tmp-promise "3.0.3"
web3-eth-abi "1.7.0"
which "2.0.2"
yaml "1.10.2"

"@graphprotocol/graph-cli@0.60.0":
version "0.60.0"
resolved "https://registry.yarnpkg.com/@graphprotocol/graph-cli/-/graph-cli-0.60.0.tgz#afcae7a966ad348886f49372d36c4ca6c35b9434"
Expand Down

0 comments on commit 08855f1

Please sign in to comment.