Skip to content

Commit 9af7113

Browse files
committed
store: Allow disabling some notifications
The notifications we send when transacting entity changes are only needed for updating GraphQL subscriptions. When that is not needed, disabling these notifications will reduce the load on Postgres' message queue
1 parent 3dff0d8 commit 9af7113

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

docs/environment-variables.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ those.
105105
- `GRAPH_SQL_STATEMENT_TIMEOUT`: the maximum number of seconds an
106106
individual SQL query is allowed to take during GraphQL
107107
execution. Default: unlimited
108+
- `GRAPH_DISABLE_SUBSCRIPTION_NOTIFICATIONS`: disables the internal
109+
mechanism that is used to trigger updates on GraphQL subscriptions. When
110+
this variable is set to any value, `graph-node` will still accept GraphQL
111+
subscriptions, but they won't receive any updates.
108112

109113
## Miscellaneous
110114

store/postgres/src/subgraph_store.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ pub struct Shard(String);
4949
lazy_static! {
5050
/// The name of the primary shard that contains all instance-wide data
5151
pub static ref PRIMARY_SHARD: Shard = Shard("primary".to_string());
52+
/// Whether to disable the notifications that feed GraphQL
53+
/// subscriptions; when the environment variable is set, no updates
54+
/// about entity changes will be sent to query nodes
55+
pub static ref SEND_SUBSCRIPTION_NOTIFICATIONS: bool = {
56+
std::env::var("GRAPH_DISABLE_SUBSCRIPTION_NOTIFICATIONS").ok().is_none()
57+
};
5258
}
5359

5460
/// How long to cache information about a deployment site
@@ -1072,7 +1078,11 @@ impl WritableStoreTrait for WritableStore {
10721078
let event = self
10731079
.writable
10741080
.revert_block_operations(self.site.clone(), block_ptr_to)?;
1075-
self.store.send_store_event(&event)
1081+
if *SEND_SUBSCRIPTION_NOTIFICATIONS {
1082+
self.store.send_store_event(&event)
1083+
} else {
1084+
Ok(())
1085+
}
10761086
}
10771087

10781088
fn unfail(&self) -> Result<(), StoreError> {
@@ -1117,7 +1127,11 @@ impl WritableStoreTrait for WritableStore {
11171127
)?;
11181128

11191129
let _section = stopwatch.start_section("send_store_event");
1120-
self.store.send_store_event(&event)
1130+
if *SEND_SUBSCRIPTION_NOTIFICATIONS {
1131+
self.store.send_store_event(&event)
1132+
} else {
1133+
Ok(())
1134+
}
11211135
}
11221136

11231137
fn get_many(

0 commit comments

Comments
 (0)