Skip to content

Commit 258cd72

Browse files
committed
node: Turn --readonly-db flag into an env var
1 parent 9e49c1c commit 258cd72

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

node/src/main.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ lazy_static! {
4949
.map(|s| u64::from_str(&s)
5050
.unwrap_or_else(|_| panic!("failed to parse env var ETHEREUM_ANCESTOR_COUNT")))
5151
.unwrap_or(50);
52+
53+
// Run against a read-only database. This turns off a few things:
54+
// - Chain head listeners
55+
// - Store events
56+
// - Subscriptions and the WebSocket server
57+
// - The JSON-RPC admin server
58+
static ref EXPERIMENTAL_READONLY_DB: bool = env::var("GRAPH_EXPERIMENTAL_READONLY_DB")
59+
.ok().is_some();
5260
}
5361

5462
git_testament!(TESTAMENT);
@@ -259,12 +267,6 @@ async fn main() {
259267
.value_name("URL")
260268
.help("HTTP endpoint for 3box profiles"),
261269
)
262-
.arg(
263-
Arg::with_name("readonly-db")
264-
.takes_value(false)
265-
.long("readonly-db")
266-
.help("Run against a readonly db (no subscriptions etc.)"),
267-
)
268270
.get_matches();
269271

270272
// Set up logger
@@ -502,9 +504,7 @@ async fn main() {
502504
connection_pool_registry,
503505
);
504506

505-
let readonly_db = matches.is_present("readonly-db");
506-
507-
let chain_head_update_listener = if readonly_db {
507+
let chain_head_update_listener = if *EXPERIMENTAL_READONLY_DB {
508508
None
509509
} else {
510510
Some(Arc::new(PostgresChainHeadUpdateListener::new(
@@ -514,7 +514,7 @@ async fn main() {
514514
)))
515515
};
516516

517-
let subscriptions = if readonly_db {
517+
let subscriptions = if *EXPERIMENTAL_READONLY_DB {
518518
None
519519
} else {
520520
Some(Arc::new(SubscriptionManager::new(
@@ -580,7 +580,7 @@ async fn main() {
580580

581581
// Disable the subscriptions server when running against a read-only
582582
// database
583-
if !readonly_db {
583+
if !*EXPERIMENTAL_READONLY_DB {
584584
let subscription_server = GraphQLSubscriptionServer::new(
585585
&logger,
586586
graphql_runner.clone(),
@@ -598,7 +598,7 @@ async fn main() {
598598
node_id.clone(),
599599
);
600600

601-
if !readonly_db {
601+
if !*EXPERIMENTAL_READONLY_DB {
602602
// Spawn Ethereum network indexers for all networks that are to be indexed
603603
if let Some(network_subgraphs) = matches.values_of("network-subgraphs") {
604604
network_subgraphs

0 commit comments

Comments
 (0)