diff --git a/node/src/bin/manager.rs b/node/src/bin/manager.rs index 603e5d65b07..d6a776d6814 100644 --- a/node/src/bin/manager.rs +++ b/node/src/bin/manager.rs @@ -406,7 +406,8 @@ pub enum StatsCommand { Show { /// The deployment (see `help info`). deployment: DeploymentSearch, - /// The name of a table to fully count + /// The name of a table to fully count which can be very slow + #[structopt(long, short)] table: Option, }, /// Perform a SQL ANALYZE in a Entity table @@ -986,7 +987,17 @@ async fn main() -> anyhow::Result<()> { clear, deployment, table, - } => commands::stats::account_like(ctx.pools(), clear, &deployment, table), + } => { + let (store, primary_pool) = ctx.store_and_primary(); + commands::stats::account_like( + store.subgraph_store(), + primary_pool, + clear, + &deployment, + table, + ) + .await + } Show { deployment, table } => { commands::stats::show(ctx.pools(), &deployment, table) } diff --git a/node/src/manager/commands/stats.rs b/node/src/manager/commands/stats.rs index c3cb6d88295..be8799b98b3 100644 --- a/node/src/manager/commands/stats.rs +++ b/node/src/manager/commands/stats.rs @@ -10,8 +10,8 @@ use diesel::PgConnection; use diesel::RunQueryDsl; use graph::prelude::anyhow; use graph::prelude::anyhow::bail; +use graph_store_postgres::command_support::catalog as store_catalog; use graph_store_postgres::command_support::catalog::Site; -use graph_store_postgres::command_support::{catalog as store_catalog, SqlName}; use graph_store_postgres::connection_pool::ConnectionPool; use graph_store_postgres::Shard; use graph_store_postgres::SubgraphStore; @@ -36,16 +36,16 @@ fn site_and_conn( Ok((site, conn)) } -pub fn account_like( - pools: HashMap, +pub async fn account_like( + store: Arc, + primary_pool: ConnectionPool, clear: bool, search: &DeploymentSearch, table: String, ) -> Result<(), anyhow::Error> { - let table = SqlName::from(table); - let (site, conn) = site_and_conn(pools, search)?; + let locator = search.locate_unique(&primary_pool)?; - store_catalog::set_account_like(&conn, &site, &table, !clear)?; + store.set_account_like(&locator, &table, !clear).await?; let clear_text = if clear { "cleared" } else { "set" }; println!("{}: account-like flag {}", table, clear_text); diff --git a/store/postgres/src/deployment_store.rs b/store/postgres/src/deployment_store.rs index d87f4d74194..9f21873674e 100644 --- a/store/postgres/src/deployment_store.rs +++ b/store/postgres/src/deployment_store.rs @@ -781,6 +781,22 @@ impl DeploymentStore { }) .await } + + pub(crate) async fn set_account_like( + &self, + site: Arc, + table: &str, + is_account_like: bool, + ) -> Result<(), StoreError> { + let store = self.clone(); + let table = table.to_string(); + self.with_conn(move |conn, _| { + let layout = store.layout(conn, site.clone())?; + let table = resolve_table_name(&layout, &table)?; + catalog::set_account_like(conn, &site, &table.name, is_account_like).map_err(Into::into) + }) + .await + } } /// Methods that back the trait `graph::components::Store`, but have small diff --git a/store/postgres/src/lib.rs b/store/postgres/src/lib.rs index 61b7e418e1d..32c20e8b817 100644 --- a/store/postgres/src/lib.rs +++ b/store/postgres/src/lib.rs @@ -69,7 +69,7 @@ pub use self::subgraph_store::{unused, DeploymentPlacer, Shard, SubgraphStore, P pub mod command_support { pub mod catalog { pub use crate::block_store::primary as block_store; - pub use crate::catalog::{account_like, set_account_like}; + pub use crate::catalog::account_like; pub use crate::copy::{copy_state, copy_table_state}; pub use crate::primary::Connection; pub use crate::primary::{ diff --git a/store/postgres/src/subgraph_store.rs b/store/postgres/src/subgraph_store.rs index 8fea9e6f6eb..23ee0358d8f 100644 --- a/store/postgres/src/subgraph_store.rs +++ b/store/postgres/src/subgraph_store.rs @@ -1044,6 +1044,16 @@ impl SubgraphStoreInner { let (store, site) = self.store(&deployment.hash)?; store.drop_index(site, index_name).await } + + pub async fn set_account_like( + &self, + deployment: &DeploymentLocator, + table: &str, + is_account_like: bool, + ) -> Result<(), StoreError> { + let (store, site) = self.store(&deployment.hash)?; + store.set_account_like(site, table, is_account_like).await + } } struct EnsLookup {