Skip to content
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
4 changes: 2 additions & 2 deletions graph/src/blockchain/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,8 +594,8 @@ impl ChainStore for MockChainStore {
}
async fn clear_stale_call_cache(
&self,
_ttl_days: i32,
_ttl_max_contracts: Option<i64>,
_ttl_days: usize,
_ttl_max_contracts: Option<usize>,
) -> Result<(), Error> {
unimplemented!()
}
Expand Down
4 changes: 2 additions & 2 deletions graph/src/components/store/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,8 +660,8 @@ pub trait ChainStore: ChainHeadStore {
/// Clears stale call cache entries for the given TTL in days.
async fn clear_stale_call_cache(
&self,
ttl_days: i32,
ttl_max_contracts: Option<i64>,
ttl_days: usize,
ttl_max_contracts: Option<usize>,
) -> Result<(), Error>;

/// Return the chain identifier for this store.
Expand Down
11 changes: 11 additions & 0 deletions graph/src/env/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ pub struct EnvVarsStore {
/// Disables storing or reading `eth_call` results from the store call cache.
/// Set by `GRAPH_STORE_DISABLE_CALL_CACHE`. Defaults to false.
pub disable_call_cache: bool,
/// The number of contracts to delete from the call cache in one batch
/// when clearing stale entries, set by
/// `GRAPH_STORE_STALE_CALL_CACHE_CONTRACTS_BATCH_SIZE`. The default
/// value is 100 contracts.
pub stale_call_cache_contracts_batch_size: usize,
/// Set by `GRAPH_STORE_DISABLE_CHAIN_HEAD_PTR_CACHE`. Default is false.
/// Set to true to disable chain_head_ptr caching (safety escape hatch).
pub disable_chain_head_ptr_cache: bool,
Expand Down Expand Up @@ -248,6 +253,7 @@ impl TryFrom<InnerStore> for EnvVarsStore {
account_like_min_versions_count: x.account_like_min_versions_count,
account_like_max_unique_ratio: x.account_like_max_unique_ratio.map(|r| r.0),
disable_call_cache: x.disable_call_cache,
stale_call_cache_contracts_batch_size: x.stale_call_cache_contracts_batch_size,
disable_chain_head_ptr_cache: x.disable_chain_head_ptr_cache,
connection_validation_idle_secs: Duration::from_secs(x.connection_validation_idle_secs),
connection_unavailable_retry: Duration::from_secs(
Expand Down Expand Up @@ -364,6 +370,11 @@ pub struct InnerStore {
account_like_max_unique_ratio: Option<ZeroToOneF64>,
#[envconfig(from = "GRAPH_STORE_DISABLE_CALL_CACHE", default = "false")]
disable_call_cache: bool,
#[envconfig(
from = "GRAPH_STORE_STALE_CALL_CACHE_CONTRACTS_BATCH_SIZE",
default = "100"
)]
stale_call_cache_contracts_batch_size: usize,
#[envconfig(from = "GRAPH_STORE_DISABLE_CHAIN_HEAD_PTR_CACHE", default = "false")]
disable_chain_head_ptr_cache: bool,
#[envconfig(from = "GRAPH_STORE_CONNECTION_VALIDATION_IDLE_SECS", default = "30")]
Expand Down
8 changes: 4 additions & 4 deletions node/src/bin/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,11 +619,11 @@ pub enum CallCacheCommand {
#[clap(long, conflicts_with_all = &["from", "to"])]
remove_entire_cache: bool,
/// Remove the cache for contracts that have not been accessed in the last <TTL_DAYS> days
#[clap(long, conflicts_with_all = &["from", "to", "remove-entire-cache"], value_parser = clap::value_parser!(i32).range(1..))]
ttl_days: Option<i32>,
#[clap(long, conflicts_with_all = &["from", "to", "remove-entire-cache"], value_parser = clap::value_parser!(u32).range(1..))]
ttl_days: Option<usize>,
/// Limits the number of contracts to consider for cache removal when using --ttl_days
#[clap(long, conflicts_with_all = &["remove-entire-cache", "to", "from"], requires = "ttl_days", value_parser = clap::value_parser!(i64).range(1..))]
ttl_max_contracts: Option<i64>,
#[clap(long, conflicts_with_all = &["remove-entire-cache", "to", "from"], requires = "ttl_days", value_parser = clap::value_parser!(u64).range(1..))]
ttl_max_contracts: Option<usize>,
/// Starting block number
#[clap(long, short, conflicts_with = "remove-entire-cache", requires = "to")]
from: Option<i32>,
Expand Down
4 changes: 2 additions & 2 deletions node/src/manager/commands/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ pub async fn clear_call_cache(

pub async fn clear_stale_call_cache(
chain_store: Arc<ChainStore>,
ttl_days: i32,
ttl_max_contracts: Option<i64>,
ttl_days: usize,
ttl_max_contracts: Option<usize>,
) -> Result<(), Error> {
println!(
"Removing stale entries from the call cache for `{}`",
Expand Down
26 changes: 26 additions & 0 deletions store/postgres/src/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,32 @@ pub(crate) async fn indexes_for_table(
Ok(results.into_iter().map(|i| i.def).collect())
}

pub(crate) async fn table_has_index(
conn: &mut AsyncPgConnection,
schema_name: &str,
index_name: &str,
) -> Result<bool, StoreError> {
#[derive(QueryableByName)]
#[allow(dead_code)]
struct Exists {
#[diesel(sql_type = diesel::sql_types::Integer)]
exists: i32,
}

let exists = sql_query(
"SELECT 1 AS exists FROM pg_indexes \
WHERE schemaname = $1 AND indexname = $2",
)
.bind::<Text, _>(schema_name)
.bind::<Text, _>(index_name)
.get_result::<Exists>(conn)
.await
.optional()
.map_err::<StoreError, _>(Into::into)?;

Ok(exists.is_some())
}

pub(crate) async fn drop_index(
conn: &mut AsyncPgConnection,
schema_name: &str,
Expand Down
Loading
Loading