Skip to content

Commit c990a29

Browse files
committed
store: Asyncify deployment::history_blocks
1 parent 2641bba commit c990a29

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

store/postgres/src/deployment.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,10 @@ impl ManifestInfo {
380380
}
381381

382382
// Return how many blocks of history this subgraph should keep
383-
pub fn history_blocks(conn: &mut PgConnection, site: &Site) -> Result<BlockNumber, StoreError> {
383+
pub async fn history_blocks(
384+
conn: &mut PgConnection,
385+
site: &Site,
386+
) -> Result<BlockNumber, StoreError> {
384387
use subgraph_manifest as sm;
385388
sm::table
386389
.select(sm::history_blocks)

store/postgres/src/relational.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ use graph::data::graphql::TypeExt as _;
3737
use graph::data::query::Trace;
3838
use graph::data::value::Word;
3939
use graph::data_source::CausalityRegion;
40-
use graph::internal_error;
4140
use graph::prelude::{q, EntityQuery, StopwatchMetrics, ENV_VARS};
4241
use graph::schema::{
4342
EntityKey, EntityType, Field, FulltextConfig, FulltextDefinition, InputSchema,
4443
};
4544
use graph::slog::warn;
45+
use graph::{internal_error, tokio};
4646
use index::IndexList;
4747
use inflector::Inflector;
4848
use itertools::Itertools;
@@ -1087,13 +1087,13 @@ impl Layout {
10871087
/// This is tied closely to how the `LayoutCache` works and called from
10881088
/// it right after creating a `Layout`, and periodically to update the
10891089
/// `Layout` in case changes were made
1090-
fn refresh(
1090+
async fn refresh(
10911091
self: Arc<Self>,
10921092
conn: &mut PgConnection,
10931093
site: Arc<Site>,
10941094
) -> Result<Arc<Self>, StoreError> {
10951095
let account_like = crate::catalog::account_like(conn, &self.site)?;
1096-
let history_blocks = deployment::history_blocks(conn, &self.site)?;
1096+
let history_blocks = deployment::history_blocks(conn, &self.site).await?;
10971097

10981098
let is_account_like = { |table: &Table| account_like.contains(table.name.as_str()) };
10991099

@@ -1750,7 +1750,7 @@ pub struct LayoutCache {
17501750
ttl: Duration,
17511751
/// Use this so that we only refresh one layout at any given time to
17521752
/// avoid refreshing the same layout multiple times
1753-
refresh: Mutex<()>,
1753+
refresh: tokio::sync::Mutex<()>,
17541754
last_sweep: Mutex<Instant>,
17551755
}
17561756

@@ -1759,7 +1759,7 @@ impl LayoutCache {
17591759
Self {
17601760
entries: Mutex::new(HashMap::new()),
17611761
ttl,
1762-
refresh: Mutex::new(()),
1762+
refresh: tokio::sync::Mutex::new(()),
17631763
last_sweep: Mutex::new(Instant::now()),
17641764
}
17651765
}
@@ -1770,7 +1770,7 @@ impl LayoutCache {
17701770
deployment::entities_with_causality_region(conn, site.id, &subgraph_schema)?;
17711771
let catalog = Catalog::load(conn, site.clone(), use_bytea_prefix, has_causality_region)?;
17721772
let layout = Arc::new(Layout::new(site.clone(), &subgraph_schema, catalog)?);
1773-
layout.refresh(conn, site)
1773+
layout.refresh(conn, site).await
17741774
}
17751775

17761776
fn cache(&self, layout: Arc<Layout>) {
@@ -1822,7 +1822,7 @@ impl LayoutCache {
18221822
if refresh.is_err() {
18231823
value
18241824
} else {
1825-
self.refresh(logger, conn, site, value)
1825+
self.refresh(logger, conn, site, value).await
18261826
}
18271827
}
18281828
}
@@ -1836,14 +1836,14 @@ impl LayoutCache {
18361836
Ok(layout)
18371837
}
18381838

1839-
fn refresh(
1839+
async fn refresh(
18401840
&self,
18411841
logger: &Logger,
18421842
conn: &mut PgConnection,
18431843
site: Arc<Site>,
18441844
value: Arc<Layout>,
18451845
) -> Arc<Layout> {
1846-
match value.cheap_clone().refresh(conn, site) {
1846+
match value.cheap_clone().refresh(conn, site).await {
18471847
Err(e) => {
18481848
warn!(
18491849
logger,

0 commit comments

Comments
 (0)