Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small improvements to graphman stats #3918

Merged
merged 2 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions node/src/bin/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
},
/// Perform a SQL ANALYZE in a Entity table
Expand Down Expand Up @@ -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)
}
Expand Down
12 changes: 6 additions & 6 deletions node/src/manager/commands/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,16 +36,16 @@ fn site_and_conn(
Ok((site, conn))
}

pub fn account_like(
pools: HashMap<Shard, ConnectionPool>,
pub async fn account_like(
store: Arc<SubgraphStore>,
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);

Expand Down
16 changes: 16 additions & 0 deletions store/postgres/src/deployment_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,22 @@ impl DeploymentStore {
})
.await
}

pub(crate) async fn set_account_like(
&self,
site: Arc<Site>,
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
Expand Down
2 changes: 1 addition & 1 deletion store/postgres/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
10 changes: 10 additions & 0 deletions store/postgres/src/subgraph_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down