Skip to content

Commit a55acf1

Browse files
committed
store: Get AsyncPgConnection from pool in chain_store
1 parent dd6df55 commit a55acf1

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

store/postgres/src/chain_store.rs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ use graph::prelude::{
3434
use graph::{ensure, internal_error};
3535

3636
use self::recent_blocks_cache::RecentBlocksCache;
37-
use crate::pool::PgConnection;
3837
use crate::AsyncPgConnection;
3938
use crate::{
4039
block_store::ChainStatus, chain_head_listener::ChainHeadUpdateSender, pool::ConnectionPool,
@@ -2022,10 +2021,6 @@ impl ChainStore {
20222021
matches!(self.status, ChainStatus::Ingestible)
20232022
}
20242023

2025-
async fn get_conn(&self) -> Result<PgConnection, Error> {
2026-
self.pool.get_sync().await.map_err(Error::from)
2027-
}
2028-
20292024
pub(crate) async fn create(&self, ident: &ChainIdentifier) -> Result<(), Error> {
20302025
use public::ethereum_networks::dsl::*;
20312026

@@ -2116,7 +2111,7 @@ impl ChainStore {
21162111
let number: Option<i64> = n::table
21172112
.filter(n::name.eq(chain))
21182113
.select(n::head_block_number)
2119-
.first::<Option<i64>>(&mut self.get_conn().await?)
2114+
.first::<Option<i64>>(&mut self.pool.get().await?)
21202115
.await
21212116
.optional()?
21222117
.flatten();
@@ -2200,14 +2195,14 @@ impl ChainStore {
22002195
}
22012196

22022197
pub async fn delete_blocks(&self, block_hashes: &[&H256]) -> Result<usize, Error> {
2203-
let mut conn = self.get_conn().await?;
2198+
let mut conn = self.pool.get().await?;
22042199
self.storage
22052200
.delete_blocks_by_hash(&mut conn, &self.chain, block_hashes)
22062201
.await
22072202
}
22082203

22092204
pub async fn cleanup_shallow_blocks(&self, lowest_block: i32) -> Result<(), StoreError> {
2210-
let mut conn = self.get_conn().await?;
2205+
let mut conn = self.pool.get().await?;
22112206
self.storage
22122207
.cleanup_shallow_blocks(&mut conn, lowest_block)
22132208
.await?;
@@ -2216,12 +2211,12 @@ impl ChainStore {
22162211

22172212
// remove_cursor delete the chain_store cursor and return true if it was present
22182213
pub async fn remove_cursor(&self, chain: &str) -> Result<Option<BlockNumber>, StoreError> {
2219-
let mut conn = self.get_conn().await?;
2214+
let mut conn = self.pool.get().await?;
22202215
self.storage.remove_cursor(&mut conn, chain).await
22212216
}
22222217

22232218
pub async fn truncate_block_cache(&self) -> Result<(), StoreError> {
2224-
let mut conn = self.get_conn().await?;
2219+
let mut conn = self.pool.get().await?;
22252220
self.storage.truncate_block_cache(&mut conn).await?;
22262221
Ok(())
22272222
}
@@ -2366,7 +2361,7 @@ impl ChainHeadStore for ChainStore {
23662361
ethereum_networks
23672362
.select(head_block_cursor)
23682363
.filter(name.eq(&self.chain))
2369-
.load::<Option<String>>(&mut self.get_conn().await?)
2364+
.load::<Option<String>>(&mut self.pool.get().await?)
23702365
.await
23712366
.map(|rows| {
23722367
rows.as_slice()
@@ -2678,7 +2673,7 @@ impl ChainStoreTrait for ChainStore {
26782673
//
26792674
// See 8b6ad0c64e244023ac20ced7897fe666
26802675

2681-
let mut conn = self.get_conn().await?;
2676+
let mut conn = self.pool.get().await?;
26822677
let query = "
26832678
select coalesce(
26842679
least(a.block,
@@ -2724,7 +2719,7 @@ impl ChainStoreTrait for ChainStore {
27242719
&self,
27252720
number: BlockNumber,
27262721
) -> Result<Vec<BlockHash>, Error> {
2727-
let mut conn = self.get_conn().await?;
2722+
let mut conn = self.pool.get().await?;
27282723
self.storage
27292724
.block_hashes_by_block_number(&mut conn, &self.chain, number)
27302725
.await
@@ -2735,7 +2730,7 @@ impl ChainStoreTrait for ChainStore {
27352730
number: BlockNumber,
27362731
hash: &BlockHash,
27372732
) -> Result<usize, Error> {
2738-
let mut conn = self.get_conn().await?;
2733+
let mut conn = self.pool.get().await?;
27392734
self.storage
27402735
.confirm_block_hash(&mut conn, &self.chain, number, hash)
27412736
.await
@@ -2768,7 +2763,7 @@ impl ChainStoreTrait for ChainStore {
27682763
}
27692764

27702765
async fn clear_call_cache(&self, from: BlockNumber, to: BlockNumber) -> Result<(), Error> {
2771-
let mut conn = self.get_conn().await?;
2766+
let mut conn = self.pool.get().await?;
27722767
if let Some(head) = self.chain_head_block(&self.chain).await? {
27732768
self.storage
27742769
.clear_call_cache(&mut conn, head, from, to)
@@ -2782,7 +2777,7 @@ impl ChainStoreTrait for ChainStore {
27822777
ttl_days: i32,
27832778
ttl_max_contracts: Option<i64>,
27842779
) -> Result<(), Error> {
2785-
let conn = &mut self.get_conn().await?;
2780+
let conn = &mut self.pool.get().await?;
27862781
self.storage
27872782
.clear_stale_call_cache(conn, &self.logger, ttl_days, ttl_max_contracts)
27882783
.await
@@ -2792,7 +2787,7 @@ impl ChainStoreTrait for ChainStore {
27922787
&self,
27932788
block_hash: &H256,
27942789
) -> Result<Vec<LightTransactionReceipt>, StoreError> {
2795-
let mut conn = self.pool.get_sync().await?;
2790+
let mut conn = self.pool.get().await?;
27962791
self.storage
27972792
.find_transaction_receipts_in_block(&mut conn, *block_hash)
27982793
.await
@@ -3042,7 +3037,7 @@ impl EthereumCallCache for ChainStore {
30423037
block: BlockPtr,
30433038
) -> Result<Option<call::Response>, Error> {
30443039
let id = contract_call_id(req, &block);
3045-
let conn = &mut self.get_conn().await?;
3040+
let conn = &mut self.pool.get().await?;
30463041
let return_value = conn
30473042
.transaction::<_, Error, _>(|conn| {
30483043
async {
@@ -3083,7 +3078,7 @@ impl EthereumCallCache for ChainStore {
30833078
.collect();
30843079
let id_refs: Vec<_> = ids.iter().map(|id| id.as_slice()).collect();
30853080

3086-
let conn = &mut self.get_conn().await?;
3081+
let conn = &mut self.pool.get().await?;
30873082
let rows = conn
30883083
.transaction::<_, Error, _>(|conn| {
30893084
self.storage
@@ -3117,7 +3112,7 @@ impl EthereumCallCache for ChainStore {
31173112
}
31183113

31193114
async fn get_calls_in_block(&self, block: BlockPtr) -> Result<Vec<CachedEthereumCall>, Error> {
3120-
let conn = &mut self.get_conn().await?;
3115+
let conn = &mut self.pool.get().await?;
31213116
conn.transaction::<_, Error, _>(|conn| {
31223117
self.storage.get_calls_in_block(conn, block).scope_boxed()
31233118
})

0 commit comments

Comments
 (0)