Skip to content

Commit 7fded19

Browse files
committed
graph, store: Simplify VersionInfo
Move hte struct to the store since it is only used for tests and remove any fields that the tests don't need
1 parent 1b4f367 commit 7fded19

File tree

8 files changed

+29
-104
lines changed

8 files changed

+29
-104
lines changed

‎graph/src/components/server/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
/// Component for running GraphQL queries over HTTP.
22
pub mod query;
33

4-
/// Component for the index node server.
5-
pub mod index_node;
6-
74
pub mod server;

‎store/postgres/src/deployment.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -318,27 +318,15 @@ pub fn schema(conn: &mut PgConnection, site: &Site) -> Result<(InputSchema, bool
318318
}
319319

320320
pub struct ManifestInfo {
321-
pub description: Option<String>,
322-
pub repository: Option<String>,
323321
pub spec_version: String,
324322
pub instrument: bool,
325323
}
326324

327325
impl ManifestInfo {
328326
pub fn load(conn: &mut PgConnection, site: &Site) -> Result<ManifestInfo, StoreError> {
329327
use subgraph_manifest as sm;
330-
let (description, repository, spec_version, features): (
331-
Option<String>,
332-
Option<String>,
333-
String,
334-
Vec<String>,
335-
) = sm::table
336-
.select((
337-
sm::description,
338-
sm::repository,
339-
sm::spec_version,
340-
sm::features,
341-
))
328+
let (spec_version, features): (String, Vec<String>) = sm::table
329+
.select((sm::spec_version, sm::features))
342330
.filter(sm::id.eq(site.id))
343331
.first(conn)?;
344332

@@ -348,8 +336,6 @@ impl ManifestInfo {
348336
let instrument = features.iter().any(|s| s == "instrument");
349337

350338
Ok(ManifestInfo {
351-
description,
352-
repository,
353339
spec_version,
354340
instrument,
355341
})

‎store/postgres/src/deployment_store.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ pub(crate) struct SubgraphInfo {
8282
/// The deployment hash of the remote subgraph whose store
8383
/// will be GraphQL queried, for debugging purposes.
8484
pub(crate) debug_fork: Option<DeploymentHash>,
85-
pub(crate) description: Option<String>,
86-
pub(crate) repository: Option<String>,
8785
pub(crate) poi_version: ProofOfIndexingVersion,
8886
pub(crate) instrument: bool,
8987
}
@@ -499,8 +497,6 @@ impl DeploymentStore {
499497
api,
500498
graft_block,
501499
debug_fork,
502-
description: manifest_info.description,
503-
repository: manifest_info.repository,
504500
poi_version,
505501
instrument: manifest_info.instrument,
506502
};

‎store/postgres/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub mod layout_for_tests {
4848
make_dummy_site, Connection, Mirror, Namespace, EVENT_TAP, EVENT_TAP_ENABLED,
4949
};
5050
pub use crate::relational::*;
51+
pub use crate::store::VersionInfo;
5152
pub mod writable {
5253
pub use crate::writable::test_support::allow_steps;
5354
}

‎store/postgres/src/primary.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -441,13 +441,12 @@ pub fn make_dummy_site(deployment: DeploymentHash, namespace: Namespace, network
441441
/// read-only
442442
mod queries {
443443
use diesel::data_types::PgTimestamp;
444-
use diesel::dsl::{exists, sql};
444+
use diesel::dsl::exists;
445445
use diesel::pg::PgConnection;
446446
use diesel::prelude::{
447447
ExpressionMethods, JoinOnDsl, NullableExpressionMethods, OptionalExtension, QueryDsl,
448448
RunQueryDsl,
449449
};
450-
use diesel::sql_types::Text;
451450
use graph::prelude::NodeId;
452451
use graph::{
453452
components::store::DeploymentId as GraphDeploymentId,
@@ -714,14 +713,14 @@ mod queries {
714713
.transpose()
715714
}
716715

717-
pub(super) fn version_info(
716+
pub(super) fn deployment_for_version(
718717
conn: &mut PgConnection,
719718
version: &str,
720-
) -> Result<Option<(String, String)>, StoreError> {
719+
) -> Result<Option<String>, StoreError> {
721720
Ok(v::table
722-
.select((v::deployment, sql::<Text>("created_at::text")))
721+
.select(v::deployment)
723722
.filter(v::id.eq(version))
724-
.first::<(String, String)>(conn)
723+
.first::<String>(conn)
725724
.optional()?)
726725
}
727726
}
@@ -2075,8 +2074,8 @@ impl Mirror {
20752074
self.read(|conn| queries::fill_assignments(conn, infos))
20762075
}
20772076

2078-
pub fn version_info(&self, version: &str) -> Result<Option<(String, String)>, StoreError> {
2079-
self.read(|conn| queries::version_info(conn, version))
2077+
pub fn deployment_for_version(&self, version: &str) -> Result<Option<String>, StoreError> {
2078+
self.read(|conn| queries::deployment_for_version(conn, version))
20802079
}
20812080

20822081
pub fn find_site_in_shard(

‎store/postgres/src/store.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@ use async_trait::async_trait;
22
use std::sync::Arc;
33

44
use graph::{
5-
components::{
6-
server::index_node::VersionInfo,
7-
store::{
8-
BlockPtrForNumber, BlockStore as BlockStoreTrait, QueryPermit, QueryStoreManager,
9-
StatusStore, Store as StoreTrait,
10-
},
5+
components::store::{
6+
BlockPtrForNumber, BlockStore as BlockStoreTrait, QueryPermit, QueryStoreManager,
7+
StatusStore, Store as StoreTrait,
118
},
129
data::subgraph::status,
1310
internal_error,
@@ -19,6 +16,14 @@ use graph::{
1916

2017
use crate::{block_store::BlockStore, query_store::QueryStore, SubgraphStore};
2118

19+
/// This is only needed for some tests
20+
#[derive(Debug)]
21+
pub struct VersionInfo {
22+
pub deployment_id: String,
23+
pub latest_ethereum_block_number: Option<BlockNumber>,
24+
pub failed: bool,
25+
}
26+
2227
/// The overall store of the system, consisting of a [`SubgraphStore`] and a
2328
/// [`BlockStore`], each of which multiplex across multiple database shards.
2429
/// The `SubgraphStore` is responsible for storing all data and metadata related
@@ -52,9 +57,7 @@ impl Store {
5257
}
5358

5459
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)?;
60+
let info = self.subgraph_store.version_info(version_id)?;
5861

5962
Ok(info)
6063
}

‎store/postgres/src/subgraph_store.rs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,9 @@ use std::{iter::FromIterator, time::Duration};
1414
use graph::futures03::future::join_all;
1515
use graph::{
1616
cheap_clone::CheapClone,
17-
components::{
18-
server::index_node::VersionInfo,
19-
store::{
20-
self, BlockPtrForNumber, BlockStore, DeploymentLocator, EnsLookup as EnsLookupTrait,
21-
PruneReporter, PruneRequest, SubgraphFork,
22-
},
17+
components::store::{
18+
self, BlockPtrForNumber, BlockStore, DeploymentLocator, EnsLookup as EnsLookupTrait,
19+
PruneReporter, PruneRequest, SubgraphFork,
2320
},
2421
data::query::QueryTarget,
2522
data::subgraph::{schema::DeploymentCreate, status, DeploymentFeatures},
@@ -44,6 +41,7 @@ use crate::{
4441
index::{IndexList, Method},
4542
Layout,
4643
},
44+
store::VersionInfo,
4745
writable::{SourceableStore, WritableStore},
4846
ConnectionPool, NotificationSender,
4947
};
@@ -981,7 +979,7 @@ impl SubgraphStoreInner {
981979
}
982980

983981
pub(crate) fn version_info(&self, version: &str) -> Result<VersionInfo, StoreError> {
984-
if let Some((deployment_id, created_at)) = self.mirror.version_info(version)? {
982+
if let Some(deployment_id) = self.mirror.deployment_for_version(version)? {
985983
let id = DeploymentHash::new(deployment_id.clone())
986984
.map_err(|id| internal_error!("illegal deployment id {}", id))?;
987985
let (store, site) = self.store(&id)?;
@@ -995,21 +993,11 @@ impl SubgraphStoreInner {
995993
.ok_or_else(|| internal_error!("no chain info for {}", deployment_id))?;
996994
let latest_ethereum_block_number =
997995
chain.latest_block.as_ref().map(|block| block.number());
998-
let subgraph_info = store.subgraph_info(site.cheap_clone())?;
999-
let layout = store.find_layout(site.cheap_clone())?;
1000-
let network = site.network.clone();
1001996

1002997
let info = VersionInfo {
1003-
created_at,
1004998
deployment_id,
1005999
latest_ethereum_block_number,
1006-
total_ethereum_blocks_count: None,
1007-
synced: status.synced,
10081000
failed: status.health.is_failed(),
1009-
description: subgraph_info.description,
1010-
repository: subgraph_info.repository,
1011-
schema: layout.input_schema.cheap_clone(),
1012-
network,
10131001
};
10141002
Ok(info)
10151003
} else {

‎store/test-store/tests/postgres/subgraph.rs

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
use graph::futures03;
22
use graph::{
3-
components::{
4-
server::index_node::VersionInfo,
5-
store::{DeploymentId, DeploymentLocator, StatusStore},
6-
},
3+
components::store::{DeploymentId, DeploymentLocator, StatusStore},
74
data::query::QueryTarget,
85
data::subgraph::{schema::SubgraphHealth, SubgraphFeature},
96
data::subgraph::{
@@ -22,7 +19,7 @@ use graph::{
2219
schema::InputSchema,
2320
semver::Version,
2421
};
25-
use graph_store_postgres::layout_for_tests::Connection as Primary;
22+
use graph_store_postgres::layout_for_tests::{Connection as Primary, VersionInfo};
2623
use graph_store_postgres::SubgraphStore;
2724
use std::{collections::HashSet, marker::PhantomData, sync::Arc};
2825
use test_store::*;
@@ -473,48 +470,6 @@ fn status() {
473470
})
474471
}
475472

476-
#[test]
477-
fn version_info() {
478-
const NAME: &str = "versionInfoSubgraph";
479-
480-
async fn setup() -> DeploymentLocator {
481-
let id = DeploymentHash::new(NAME).unwrap();
482-
remove_subgraphs();
483-
block_store::set_chain(vec![], NETWORK_NAME).await;
484-
create_test_subgraph(&id, SUBGRAPH_GQL).await
485-
}
486-
487-
run_test_sequentially(|store| async move {
488-
let deployment = setup().await;
489-
transact_and_wait(
490-
&store.subgraph_store(),
491-
&deployment,
492-
BLOCK_ONE.clone(),
493-
vec![],
494-
)
495-
.await
496-
.unwrap();
497-
498-
let vi = get_version_info(&store, NAME);
499-
assert_eq!(NAME, vi.deployment_id.as_str());
500-
assert_eq!(false, vi.synced);
501-
assert_eq!(false, vi.failed);
502-
assert_eq!(
503-
Some("manifest for versionInfoSubgraph"),
504-
vi.description.as_deref()
505-
);
506-
assert_eq!(
507-
Some("repo for versionInfoSubgraph"),
508-
vi.repository.as_deref()
509-
);
510-
assert_eq!(NAME, vi.schema.id().as_str());
511-
assert_eq!(Some(1), vi.latest_ethereum_block_number);
512-
assert_eq!(NETWORK_NAME, vi.network.as_str());
513-
// We set the head for the network to null in the test framework
514-
assert_eq!(None, vi.total_ethereum_blocks_count);
515-
})
516-
}
517-
518473
#[test]
519474
fn subgraph_features() {
520475
run_test_sequentially(|_store| async move {

0 commit comments

Comments
 (0)