Skip to content

Commit d5c82b5

Browse files
incrypto32lutter
authored andcommitted
Revert "graph: Remove unneeded methods from StatusStore trait"
This reverts commit a383f5e.
1 parent a349d98 commit d5c82b5

File tree

4 files changed

+112
-10
lines changed

4 files changed

+112
-10
lines changed

graph/src/components/store/traits.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use super::*;
99
use crate::blockchain::block_stream::{EntitySourceOperation, FirehoseCursor};
1010
use crate::blockchain::{BlockTime, ChainIdentifier, ExtendedBlockPtr};
1111
use crate::components::metrics::stopwatch::StopwatchMetrics;
12+
use crate::components::server::index_node::VersionInfo;
1213
use crate::components::subgraph::SubgraphVersionSwitchingMode;
1314
use crate::components::transaction_receipt;
1415
use crate::components::versions::ApiVersion;
@@ -686,6 +687,25 @@ pub trait StatusStore: Send + Sync + 'static {
686687

687688
fn status(&self, filter: status::Filter) -> Result<Vec<status::Info>, StoreError>;
688689

690+
/// Support for the explorer-specific API
691+
fn version_info(&self, version_id: &str) -> Result<VersionInfo, StoreError>;
692+
693+
/// Support for the explorer-specific API; note that `subgraph_id` must be
694+
/// the id of an entry in `subgraphs.subgraph`, not that of a deployment.
695+
/// The return values are the ids of the `subgraphs.subgraph_version` for
696+
/// the current and pending versions of the subgraph
697+
fn versions_for_subgraph_id(
698+
&self,
699+
subgraph_id: &str,
700+
) -> Result<(Option<String>, Option<String>), StoreError>;
701+
702+
/// Support for the explorer-specific API. Returns a vector of (name, version) of all
703+
/// subgraphs for a given deployment hash.
704+
fn subgraphs_for_deployment_hash(
705+
&self,
706+
deployment_hash: &str,
707+
) -> Result<Vec<(String, String)>, StoreError>;
708+
689709
/// A value of None indicates that the table is not available. Re-deploying
690710
/// the subgraph fixes this. It is undesirable to force everything to
691711
/// re-sync from scratch, so existing deployments will continue without a

store/postgres/src/primary.rs

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,8 @@ mod queries {
444444
use diesel::dsl::{exists, sql};
445445
use diesel::pg::PgConnection;
446446
use diesel::prelude::{
447-
ExpressionMethods, JoinOnDsl, NullableExpressionMethods, OptionalExtension, QueryDsl,
448-
RunQueryDsl,
447+
BoolExpressionMethods, ExpressionMethods, JoinOnDsl, NullableExpressionMethods,
448+
OptionalExtension, QueryDsl, RunQueryDsl,
449449
};
450450
use diesel::sql_types::Text;
451451
use graph::prelude::NodeId;
@@ -724,6 +724,44 @@ mod queries {
724724
.first::<(String, String)>(conn)
725725
.optional()?)
726726
}
727+
728+
pub(super) fn versions_for_subgraph_id(
729+
conn: &mut PgConnection,
730+
subgraph_id: &str,
731+
) -> Result<(Option<String>, Option<String>), StoreError> {
732+
Ok(s::table
733+
.select((s::current_version.nullable(), s::pending_version.nullable()))
734+
.filter(s::id.eq(subgraph_id))
735+
.first::<(Option<String>, Option<String>)>(conn)
736+
.optional()?
737+
.unwrap_or((None, None)))
738+
}
739+
740+
/// Returns all (subgraph_name, version) pairs for a given deployment hash.
741+
pub fn subgraphs_by_deployment_hash(
742+
conn: &mut PgConnection,
743+
deployment_hash: &str,
744+
) -> Result<Vec<(String, String)>, StoreError> {
745+
v::table
746+
.inner_join(
747+
s::table.on(v::id
748+
.nullable()
749+
.eq(s::current_version)
750+
.or(v::id.nullable().eq(s::pending_version))),
751+
)
752+
.filter(v::deployment.eq(&deployment_hash))
753+
.select((
754+
s::name,
755+
sql::<Text>(
756+
"(case when subgraphs.subgraph.pending_version = subgraphs.subgraph_version.id then 'pending'
757+
when subgraphs.subgraph.current_version = subgraphs.subgraph_version.id then 'current'
758+
else 'unused'
759+
end) as version",
760+
),
761+
))
762+
.get_results(conn)
763+
.map_err(Into::into)
764+
}
727765
}
728766

729767
/// A wrapper for a database connection that provides access to functionality
@@ -2079,6 +2117,21 @@ impl Mirror {
20792117
self.read(|conn| queries::version_info(conn, version))
20802118
}
20812119

2120+
pub fn versions_for_subgraph_id(
2121+
&self,
2122+
subgraph_id: &str,
2123+
) -> Result<(Option<String>, Option<String>), StoreError> {
2124+
self.read(|conn| queries::versions_for_subgraph_id(conn, subgraph_id))
2125+
}
2126+
2127+
/// Returns all (subgraph_name, version) pairs for a given deployment hash.
2128+
pub fn subgraphs_by_deployment_hash(
2129+
&self,
2130+
deployment_hash: &str,
2131+
) -> Result<Vec<(String, String)>, StoreError> {
2132+
self.read(|conn| queries::subgraphs_by_deployment_hash(conn, deployment_hash))
2133+
}
2134+
20822135
pub fn find_site_in_shard(
20832136
&self,
20842137
subgraph: &DeploymentHash,

store/postgres/src/store.rs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,6 @@ impl Store {
5050
pub fn block_store(&self) -> Arc<BlockStore> {
5151
self.block_store.cheap_clone()
5252
}
53-
54-
pub fn version_info(&self, version_id: &str) -> Result<VersionInfo, StoreError> {
55-
let mut info = self.subgraph_store.version_info(version_id)?;
56-
57-
info.total_ethereum_blocks_count = self.block_store.chain_head_block(&info.network)?;
58-
59-
Ok(info)
60-
}
6153
}
6254

6355
impl StoreTrait for Store {
@@ -125,6 +117,29 @@ impl StatusStore for Store {
125117
Ok(infos)
126118
}
127119

120+
fn version_info(&self, version_id: &str) -> Result<VersionInfo, StoreError> {
121+
let mut info = self.subgraph_store.version_info(version_id)?;
122+
123+
info.total_ethereum_blocks_count = self.block_store.chain_head_block(&info.network)?;
124+
125+
Ok(info)
126+
}
127+
128+
fn versions_for_subgraph_id(
129+
&self,
130+
subgraph_id: &str,
131+
) -> Result<(Option<String>, Option<String>), StoreError> {
132+
self.subgraph_store.versions_for_subgraph_id(subgraph_id)
133+
}
134+
135+
fn subgraphs_for_deployment_hash(
136+
&self,
137+
deployment_hash: &str,
138+
) -> Result<Vec<(String, String)>, StoreError> {
139+
self.subgraph_store
140+
.subgraphs_for_deployment_hash(deployment_hash)
141+
}
142+
128143
async fn get_proof_of_indexing(
129144
&self,
130145
subgraph_id: &DeploymentHash,

store/postgres/src/subgraph_store.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,20 @@ impl SubgraphStoreInner {
10181018
}
10191019
}
10201020

1021+
pub(crate) fn versions_for_subgraph_id(
1022+
&self,
1023+
subgraph_id: &str,
1024+
) -> Result<(Option<String>, Option<String>), StoreError> {
1025+
self.mirror.versions_for_subgraph_id(subgraph_id)
1026+
}
1027+
1028+
pub(crate) fn subgraphs_for_deployment_hash(
1029+
&self,
1030+
deployment_hash: &str,
1031+
) -> Result<Vec<(String, String)>, StoreError> {
1032+
self.mirror.subgraphs_by_deployment_hash(deployment_hash)
1033+
}
1034+
10211035
#[cfg(debug_assertions)]
10221036
pub fn error_count(&self, id: &DeploymentHash) -> Result<usize, StoreError> {
10231037
let (store, _) = self.store(id)?;

0 commit comments

Comments
 (0)