diff --git a/chain/substreams/src/trigger.rs b/chain/substreams/src/trigger.rs index 4eca20ae0e1..ecf04939096 100644 --- a/chain/substreams/src/trigger.rs +++ b/chain/substreams/src/trigger.rs @@ -4,7 +4,7 @@ use anyhow::Error; use graph::{ blockchain::{self, block_stream::BlockWithTriggers, BlockPtr}, components::{ - store::{DeploymentLocator, EntityRef, SubgraphFork}, + store::{DeploymentLocator, EntityKey, SubgraphFork}, subgraph::{MappingError, ProofOfIndexingEvent, SharedProofOfIndexing}, }, data::store::scalar::Bytes, @@ -150,7 +150,7 @@ where let entity_type: &str = &entity_change.entity; let entity_id: String = String::from_utf8(entity_change.id.clone()) .map_err(|e| MappingError::Unknown(anyhow::Error::from(e)))?; - let key = EntityRef::data(entity_type.to_string(), entity_id.clone()); + let key = EntityKey::data(entity_type.to_string(), entity_id.clone()); let mut data: HashMap = HashMap::from_iter(vec![]); for field in entity_change.fields.iter() { @@ -205,7 +205,7 @@ where let entity_type: &str = &entity_change.entity; let entity_id: String = String::from_utf8(entity_change.id.clone()) .map_err(|e| MappingError::Unknown(anyhow::Error::from(e)))?; - let key = EntityRef::data(entity_type.to_string(), entity_id.clone()); + let key = EntityKey::data(entity_type.to_string(), entity_id.clone()); state.entity_cache.remove(key); diff --git a/core/src/subgraph/runner.rs b/core/src/subgraph/runner.rs index 6a1d5bacc8b..2fed3d6dced 100644 --- a/core/src/subgraph/runner.rs +++ b/core/src/subgraph/runner.rs @@ -6,7 +6,7 @@ use crate::subgraph::stream::new_block_stream; use atomic_refcell::AtomicRefCell; use graph::blockchain::block_stream::{BlockStreamEvent, BlockWithTriggers, FirehoseCursor}; use graph::blockchain::{Block, Blockchain, DataSource, TriggerFilter as _}; -use graph::components::store::EntityRef; +use graph::components::store::EntityKey; use graph::components::{ store::ModificationsAndCache, subgraph::{CausalityRegion, MappingError, ProofOfIndexing, SharedProofOfIndexing}, @@ -867,7 +867,7 @@ async fn update_proof_of_indexing( for (causality_region, stream) in proof_of_indexing.drain() { // Create the special POI entity key specific to this causality_region - let entity_key = EntityRef { + let entity_key = EntityKey { entity_type: POI_OBJECT.to_owned(), entity_id: causality_region.into(), }; diff --git a/core/src/subgraph/state.rs b/core/src/subgraph/state.rs index b3ed45cb49f..0d5edd84b65 100644 --- a/core/src/subgraph/state.rs +++ b/core/src/subgraph/state.rs @@ -1,5 +1,5 @@ use graph::{ - components::store::EntityRef, + components::store::EntityKey, prelude::Entity, util::{backoff::ExponentialBackoff, lfu_cache::LfuCache}, }; @@ -18,5 +18,5 @@ pub struct IndexingState { /// - The time THRESHOLD is passed /// - Or the subgraph has triggers for the block pub skip_ptr_updates_timer: Instant, - pub entity_lfu_cache: LfuCache>, + pub entity_lfu_cache: LfuCache>, } diff --git a/graph/src/components/store/cache.rs b/graph/src/components/store/cache.rs index 38ff5f2c74b..90f40e3c72c 100644 --- a/graph/src/components/store/cache.rs +++ b/graph/src/components/store/cache.rs @@ -6,7 +6,7 @@ use std::sync::Arc; use crate::blockchain::BlockPtr; use crate::blockchain::DataSource; use crate::components::store::{ - self as s, Entity, EntityOp, EntityOperation, EntityRef, EntityType, + self as s, Entity, EntityKey, EntityOp, EntityOperation, EntityType, }; use crate::prelude::ENV_VARS; use crate::util::lfu_cache::LfuCache; @@ -21,13 +21,13 @@ use crate::util::lfu_cache::LfuCache; pub struct EntityCache { /// The state of entities in the store. An entry of `None` /// means that the entity is not present in the store - current: LfuCache>, + current: LfuCache>, /// The accumulated changes to an entity. - updates: HashMap, + updates: HashMap, // Updates for a currently executing handler. - handler_updates: HashMap, + handler_updates: HashMap, // Marks whether updates should go in `handler_updates`. in_handler: bool, @@ -50,7 +50,7 @@ impl Debug for EntityCache { pub struct ModificationsAndCache { pub modifications: Vec, pub data_sources: Vec, - pub entity_lfu_cache: LfuCache>, + pub entity_lfu_cache: LfuCache>, } impl EntityCache { @@ -67,7 +67,7 @@ impl EntityCache { pub fn with_current( store: Arc, - current: LfuCache>, + current: LfuCache>, ) -> EntityCache { EntityCache { current, @@ -101,7 +101,7 @@ impl EntityCache { self.handler_updates.clear(); } - pub fn get(&mut self, eref: &EntityRef) -> Result, s::QueryExecutionError> { + pub fn get(&mut self, eref: &EntityKey) -> Result, s::QueryExecutionError> { // Get the current entity, apply any updates from `updates`, then // from `handler_updates`. let mut entity = self.current.get_entity(&*self.store, eref)?; @@ -114,7 +114,7 @@ impl EntityCache { Ok(entity) } - pub fn remove(&mut self, key: EntityRef) { + pub fn remove(&mut self, key: EntityKey) { self.entity_op(key, EntityOp::Remove); } @@ -123,8 +123,8 @@ impl EntityCache { /// with existing data. The entity will be validated against the /// subgraph schema, and any errors will result in an `Err` being /// returned. - pub fn set(&mut self, key: EntityRef, mut entity: Entity) -> Result<(), anyhow::Error> { - fn check_id(key: &EntityRef, prev_id: &str) -> Result<(), anyhow::Error> { + pub fn set(&mut self, key: EntityKey, mut entity: Entity) -> Result<(), anyhow::Error> { + fn check_id(key: &EntityKey, prev_id: &str) -> Result<(), anyhow::Error> { if prev_id != key.entity_id.as_str() { return Err(anyhow!( "Value of {} attribute 'id' conflicts with ID passed to `store.set()`: \ @@ -194,7 +194,7 @@ impl EntityCache { .push(data_source.as_stored_dynamic_data_source()); } - fn entity_op(&mut self, key: EntityRef, op: EntityOp) { + fn entity_op(&mut self, key: EntityKey, op: EntityOp) { use std::collections::hash_map::Entry; let updates = match self.in_handler { true => &mut self.handler_updates, @@ -253,7 +253,7 @@ impl EntityCache { for (entity_type, entities) in self.store.get_many(missing_by_type)? { for entity in entities { - let key = EntityRef { + let key = EntityKey { entity_type: entity_type.clone(), entity_id: entity.id().unwrap().into(), }; @@ -317,12 +317,12 @@ impl EntityCache { } } -impl LfuCache> { +impl LfuCache> { // Helper for cached lookup of an entity. fn get_entity( &mut self, store: &(impl s::WritableStore + ?Sized), - key: &EntityRef, + key: &EntityKey, ) -> Result, s::QueryExecutionError> { match self.get(key) { None => { diff --git a/graph/src/components/store/mod.rs b/graph/src/components/store/mod.rs index eaa2124c498..009913d6d28 100644 --- a/graph/src/components/store/mod.rs +++ b/graph/src/components/store/mod.rs @@ -96,7 +96,7 @@ impl EntityFilterDerivative { /// Key by which an individual entity in the store can be accessed. Stores /// only the entity type and id. The deployment must be known from context. #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct EntityRef { +pub struct EntityKey { /// Name of the entity type. pub entity_type: EntityType, @@ -104,7 +104,7 @@ pub struct EntityRef { pub entity_id: Word, } -impl EntityRef { +impl EntityKey { pub fn data(entity_type: String, entity_id: String) -> Self { Self { entity_type: EntityType::new(entity_type), @@ -536,7 +536,7 @@ pub enum EntityChange { } impl EntityChange { - pub fn for_data(subgraph_id: DeploymentHash, key: EntityRef) -> Self { + pub fn for_data(subgraph_id: DeploymentHash, key: EntityKey) -> Self { Self::Data { subgraph_id: subgraph_id, entity_type: key.entity_type, @@ -781,10 +781,10 @@ where pub enum EntityOperation { /// Locates the entity specified by `key` and sets its attributes according to the contents of /// `data`. If no entity exists with this key, creates a new entity. - Set { key: EntityRef, data: Entity }, + Set { key: EntityKey, data: Entity }, /// Removes an entity with the specified key, if one exists. - Remove { key: EntityRef }, + Remove { key: EntityKey }, } #[derive(Debug, PartialEq)] @@ -865,15 +865,15 @@ pub type PoolWaitStats = Arc>; #[derive(Clone, Debug, PartialEq, Eq)] pub enum EntityModification { /// Insert the entity - Insert { key: EntityRef, data: Entity }, + Insert { key: EntityKey, data: Entity }, /// Update the entity by overwriting it - Overwrite { key: EntityRef, data: Entity }, + Overwrite { key: EntityKey, data: Entity }, /// Remove the entity - Remove { key: EntityRef }, + Remove { key: EntityKey }, } impl EntityModification { - pub fn entity_ref(&self) -> &EntityRef { + pub fn entity_ref(&self) -> &EntityKey { use EntityModification::*; match self { Insert { key, .. } | Overwrite { key, .. } | Remove { key } => key, diff --git a/graph/src/components/store/traits.rs b/graph/src/components/store/traits.rs index b86ce167baf..1bfeb03d9da 100644 --- a/graph/src/components/store/traits.rs +++ b/graph/src/components/store/traits.rs @@ -191,7 +191,7 @@ pub trait WritableStore: Send + Sync + 'static { async fn supports_proof_of_indexing(&self) -> Result; /// Looks up an entity using the given store key at the latest block. - fn get(&self, key: &EntityRef) -> Result, StoreError>; + fn get(&self, key: &EntityKey) -> Result, StoreError>; /// Transact the entity changes from a single block atomically into the store, and update the /// subgraph block pointer to `block_ptr_to`, and update the firehose cursor to `firehose_cursor` diff --git a/graph/src/components/subgraph/instance.rs b/graph/src/components/subgraph/instance.rs index cdcd902404a..915f3f99a32 100644 --- a/graph/src/components/subgraph/instance.rs +++ b/graph/src/components/subgraph/instance.rs @@ -1,5 +1,5 @@ use crate::blockchain::Blockchain; -use crate::components::store::EntityRef; +use crate::components::store::EntityKey; use crate::prelude::*; use crate::util::lfu_cache::LfuCache; use crate::{components::store::WritableStore, data::subgraph::schema::SubgraphError}; @@ -28,7 +28,7 @@ pub struct BlockState { impl BlockState { pub fn new( store: Arc, - lfu_cache: LfuCache>, + lfu_cache: LfuCache>, ) -> Self { BlockState { entity_cache: EntityCache::with_current(store, lfu_cache), diff --git a/graph/src/data/schema.rs b/graph/src/data/schema.rs index 4abcbc13ac6..20de5cdfba4 100644 --- a/graph/src/data/schema.rs +++ b/graph/src/data/schema.rs @@ -1,5 +1,5 @@ use crate::cheap_clone::CheapClone; -use crate::components::store::{EntityRef, EntityType, SubgraphStore}; +use crate::components::store::{EntityKey, EntityType, SubgraphStore}; use crate::data::graphql::ext::{DirectiveExt, DirectiveFinder, DocumentExt, TypeExt, ValueExt}; use crate::data::graphql::ObjectTypeExt; use crate::data::store::{self, ValueType}; @@ -608,7 +608,7 @@ impl Schema { } /// Construct a value for the entity type's id attribute - pub fn id_value(&self, key: &EntityRef) -> Result { + pub fn id_value(&self, key: &EntityKey) -> Result { let base_type = self .document .get_object_type_definition(key.entity_type.as_str()) diff --git a/graph/src/data/store/mod.rs b/graph/src/data/store/mod.rs index 60324ac8584..8a03e3ce0ff 100644 --- a/graph/src/data/store/mod.rs +++ b/graph/src/data/store/mod.rs @@ -1,5 +1,5 @@ use crate::{ - components::store::{DeploymentLocator, EntityRef, EntityType}, + components::store::{DeploymentLocator, EntityKey, EntityType}, data::graphql::ObjectTypeExt, prelude::{anyhow::Context, q, r, s, CacheWeight, QueryExecutionError, Schema}, runtime::gas::{Gas, GasSizeOf}, @@ -700,7 +700,7 @@ impl Entity { /// Validate that this entity matches the object type definition in the /// schema. An entity that passes these checks can be stored /// successfully in the subgraph's database schema - pub fn validate(&self, schema: &Schema, key: &EntityRef) -> Result<(), anyhow::Error> { + pub fn validate(&self, schema: &Schema, key: &EntityKey) -> Result<(), anyhow::Error> { fn scalar_value_type(schema: &Schema, field_type: &s::Type) -> ValueType { use s::TypeDefinition as t; match field_type { @@ -938,7 +938,7 @@ fn entity_validation() { let schema = crate::prelude::Schema::parse(DOCUMENT, subgraph).expect("Failed to parse test schema"); let id = thing.id().unwrap_or("none".to_owned()); - let key = EntityRef::data("Thing".to_owned(), id.clone()); + let key = EntityKey::data("Thing".to_owned(), id.clone()); let err = thing.validate(&schema, &key); if errmsg == "" { diff --git a/graph/src/runtime/gas/size_of.rs b/graph/src/runtime/gas/size_of.rs index 35e9bbfbbb4..49bb60b1215 100644 --- a/graph/src/runtime/gas/size_of.rs +++ b/graph/src/runtime/gas/size_of.rs @@ -1,7 +1,7 @@ //! Various implementations of GasSizeOf; use crate::{ - components::store::{EntityRef, EntityType}, + components::store::{EntityKey, EntityType}, data::store::{scalar::Bytes, Value}, prelude::{BigDecimal, BigInt}, }; @@ -162,7 +162,7 @@ impl GasSizeOf for usize { } } -impl GasSizeOf for EntityRef { +impl GasSizeOf for EntityKey { fn gas_size_of(&self) -> Gas { self.entity_type.gas_size_of() + self.entity_id.gas_size_of() } diff --git a/graph/src/util/cache_weight.rs b/graph/src/util/cache_weight.rs index e11498faabd..af15a82b25d 100644 --- a/graph/src/util/cache_weight.rs +++ b/graph/src/util/cache_weight.rs @@ -1,5 +1,5 @@ use crate::{ - components::store::{EntityRef, EntityType}, + components::store::{EntityKey, EntityType}, data::value::Word, prelude::{q, BigDecimal, BigInt, Value}, }; @@ -121,7 +121,7 @@ impl CacheWeight for EntityType { } } -impl CacheWeight for EntityRef { +impl CacheWeight for EntityKey { fn indirect_weight(&self) -> usize { self.entity_id.indirect_weight() + self.entity_type.indirect_weight() } diff --git a/graph/tests/entity_cache.rs b/graph/tests/entity_cache.rs index 75036cc0d54..1f0cf594e7b 100644 --- a/graph/tests/entity_cache.rs +++ b/graph/tests/entity_cache.rs @@ -8,7 +8,7 @@ use slog::Logger; use std::collections::BTreeMap; use std::sync::Arc; -use graph::components::store::{EntityRef, EntityType, StoredDynamicDataSource, WritableStore}; +use graph::components::store::{EntityKey, EntityType, StoredDynamicDataSource, WritableStore}; use graph::{ components::store::{DeploymentId, DeploymentLocator}, prelude::{anyhow, DeploymentHash, Entity, EntityCache, EntityModification, Value}, @@ -86,7 +86,7 @@ impl WritableStore for MockStore { unimplemented!() } - fn get(&self, key: &EntityRef) -> Result, StoreError> { + fn get(&self, key: &EntityKey) -> Result, StoreError> { match self.get_many_res.get(&key.entity_type) { Some(entities) => Ok(entities .iter() @@ -155,9 +155,9 @@ impl WritableStore for MockStore { } } -fn make_band(id: &'static str, data: Vec<(&str, Value)>) -> (EntityRef, Entity) { +fn make_band(id: &'static str, data: Vec<(&str, Value)>) -> (EntityKey, Entity) { ( - EntityRef { + EntityKey { entity_type: EntityType::new("Band".to_string()), entity_id: id.into(), }, diff --git a/graphql/src/schema/ast.rs b/graphql/src/schema/ast.rs index 5d761d3a9c7..6460f244eac 100644 --- a/graphql/src/schema/ast.rs +++ b/graphql/src/schema/ast.rs @@ -399,7 +399,7 @@ pub fn is_list(field_type: &s::Type) -> bool { #[test] fn entity_validation() { - use graph::components::store::EntityRef; + use graph::components::store::EntityKey; use graph::data::store; use graph::prelude::{DeploymentHash, Entity}; @@ -435,7 +435,7 @@ fn entity_validation() { let schema = graph::prelude::Schema::parse(DOCUMENT, subgraph).expect("Failed to parse test schema"); let id = thing.id().unwrap_or("none".to_owned()); - let key = EntityRef::data("Thing".to_owned(), id.clone()); + let key = EntityKey::data("Thing".to_owned(), id.clone()); let err = thing.validate(&schema, &key); if errmsg == "" { diff --git a/graphql/tests/query.rs b/graphql/tests/query.rs index 525dce202d5..5e9f4944f47 100644 --- a/graphql/tests/query.rs +++ b/graphql/tests/query.rs @@ -1,7 +1,7 @@ #[macro_use] extern crate pretty_assertions; -use graph::components::store::{EntityRef, EntityType}; +use graph::components::store::{EntityKey, EntityType}; use graph::data::subgraph::schema::DeploymentCreate; use graph::entity; use graph::prelude::SubscriptionResult; @@ -222,7 +222,7 @@ async fn insert_test_entities( async fn insert_at(entities: Vec, deployment: &DeploymentLocator, block_ptr: BlockPtr) { let insert_ops = entities.into_iter().map(|data| EntityOperation::Set { - key: EntityRef { + key: EntityKey { entity_type: EntityType::new( data.get("__typename").unwrap().clone().as_string().unwrap(), ), diff --git a/runtime/test/src/test.rs b/runtime/test/src/test.rs index 41861da3bcc..b384bace4dd 100644 --- a/runtime/test/src/test.rs +++ b/runtime/test/src/test.rs @@ -423,7 +423,7 @@ fn make_thing(id: &str, value: &str) -> (String, EntityModification) { data.set("id", id); data.set("value", value); data.set("extra", USER_DATA); - let key = EntityRef { + let key = EntityKey { entity_type: EntityType::new("Thing".to_string()), entity_id: id.into(), }; diff --git a/runtime/wasm/src/host_exports.rs b/runtime/wasm/src/host_exports.rs index a3a72e6232b..1acce38d7e6 100644 --- a/runtime/wasm/src/host_exports.rs +++ b/runtime/wasm/src/host_exports.rs @@ -11,7 +11,7 @@ use web3::types::H160; use graph::blockchain::DataSource; use graph::blockchain::{Blockchain, DataSourceTemplate as _}; use graph::components::store::EnsLookup; -use graph::components::store::{EntityRef, EntityType}; +use graph::components::store::{EntityKey, EntityType}; use graph::components::subgraph::{CausalityRegion, ProofOfIndexingEvent, SharedProofOfIndexing}; use graph::data::store; use graph::ensure; @@ -150,7 +150,7 @@ impl HostExports { ); poi_section.end(); - let key = EntityRef { + let key = EntityKey { entity_type: EntityType::new(entity_type), entity_id: entity_id.into(), }; @@ -181,7 +181,7 @@ impl HostExports { &self.causality_region, logger, ); - let key = EntityRef { + let key = EntityKey { entity_type: EntityType::new(entity_type), entity_id: entity_id.into(), }; @@ -200,7 +200,7 @@ impl HostExports { entity_id: String, gas: &GasCounter, ) -> Result, anyhow::Error> { - let store_key = EntityRef { + let store_key = EntityKey { entity_type: EntityType::new(entity_type), entity_id: entity_id.into(), }; diff --git a/store/postgres/src/deployment_store.rs b/store/postgres/src/deployment_store.rs index 1b68ed0e50e..82874393e4e 100644 --- a/store/postgres/src/deployment_store.rs +++ b/store/postgres/src/deployment_store.rs @@ -4,7 +4,7 @@ use diesel::pg::PgConnection; use diesel::prelude::*; use diesel::r2d2::{ConnectionManager, PooledConnection}; use graph::blockchain::block_stream::FirehoseCursor; -use graph::components::store::{EntityRef, EntityType, StoredDynamicDataSource}; +use graph::components::store::{EntityKey, EntityType, StoredDynamicDataSource}; use graph::data::query::Trace; use graph::data::subgraph::{status, SPEC_VERSION_0_0_6}; use graph::prelude::{ @@ -251,7 +251,7 @@ impl DeploymentStore { &self, conn: &PgConnection, layout: &Layout, - key: &EntityRef, + key: &EntityKey, ) -> Result<(), StoreError> { // Collect all types that share an interface implementation with this // entity type, and make sure there are no conflicting IDs. @@ -360,7 +360,7 @@ impl DeploymentStore { fn insert_entities<'a>( &'a self, entity_type: &'a EntityType, - data: &'a mut [(&'a EntityRef, Cow<'a, Entity>)], + data: &'a mut [(&'a EntityKey, Cow<'a, Entity>)], conn: &PgConnection, layout: &'a Layout, ptr: &BlockPtr, @@ -380,7 +380,7 @@ impl DeploymentStore { fn overwrite_entities<'a>( &'a self, entity_type: &'a EntityType, - data: &'a mut [(&'a EntityRef, Cow<'a, Entity>)], + data: &'a mut [(&'a EntityKey, Cow<'a, Entity>)], conn: &PgConnection, layout: &'a Layout, ptr: &BlockPtr, @@ -916,7 +916,7 @@ impl DeploymentStore { pub(crate) fn get( &self, site: Arc, - key: &EntityRef, + key: &EntityKey, block: BlockNumber, ) -> Result, StoreError> { let conn = self.get_conn()?; diff --git a/store/postgres/src/relational.rs b/store/postgres/src/relational.rs index 30e2ee53f8b..a71639a9e42 100644 --- a/store/postgres/src/relational.rs +++ b/store/postgres/src/relational.rs @@ -41,7 +41,7 @@ use crate::{ FilterQuery, FindManyQuery, FindQuery, InsertQuery, RevertClampQuery, RevertRemoveQuery, }, }; -use graph::components::store::{EntityRef, EntityType}; +use graph::components::store::{EntityKey, EntityType}; use graph::data::graphql::ext::{DirectiveFinder, DocumentExt, ObjectTypeExt}; use graph::data::schema::{FulltextConfig, FulltextDefinition, Schema, SCHEMA_TYPE_NAME}; use graph::data::store::BYTES_SCALAR; @@ -555,7 +555,7 @@ impl Layout { .expect("__typename expected; this is a bug"); changes.push(EntityOperation::Set { - key: EntityRef { + key: EntityKey { entity_type, entity_id, }, @@ -571,7 +571,7 @@ impl Layout { // about why this check is necessary. if !processed_entities.contains(&(entity_type.clone(), entity_id.clone())) { changes.push(EntityOperation::Remove { - key: EntityRef { + key: EntityKey { entity_type, entity_id, }, @@ -586,7 +586,7 @@ impl Layout { &'a self, conn: &PgConnection, entity_type: &'a EntityType, - entities: &'a mut [(&'a EntityRef, Cow<'a, Entity>)], + entities: &'a mut [(&'a EntityKey, Cow<'a, Entity>)], block: BlockNumber, stopwatch: &StopwatchMetrics, ) -> Result { @@ -726,7 +726,7 @@ impl Layout { &'a self, conn: &PgConnection, entity_type: &'a EntityType, - entities: &'a mut [(&'a EntityRef, Cow<'a, Entity>)], + entities: &'a mut [(&'a EntityKey, Cow<'a, Entity>)], block: BlockNumber, stopwatch: &StopwatchMetrics, ) -> Result { diff --git a/store/postgres/src/relational_queries.rs b/store/postgres/src/relational_queries.rs index 35a5ce599d0..e62de38f14c 100644 --- a/store/postgres/src/relational_queries.rs +++ b/store/postgres/src/relational_queries.rs @@ -12,7 +12,7 @@ use diesel::result::{Error as DieselError, QueryResult}; use diesel::sql_types::{Array, BigInt, Binary, Bool, Integer, Jsonb, Text}; use diesel::Connection; -use graph::components::store::EntityRef; +use graph::components::store::EntityKey; use graph::data::value::Word; use graph::prelude::{ anyhow, r, serde_json, Attribute, BlockNumber, ChildMultiplicity, Entity, EntityCollection, @@ -1646,7 +1646,7 @@ impl<'a, Conn> RunQueryDsl for FindManyQuery<'a> {} #[derive(Debug)] pub struct InsertQuery<'a> { table: &'a Table, - entities: &'a [(&'a EntityRef, Cow<'a, Entity>)], + entities: &'a [(&'a EntityKey, Cow<'a, Entity>)], unique_columns: Vec<&'a Column>, br_column: BlockRangeColumn<'a>, } @@ -1654,7 +1654,7 @@ pub struct InsertQuery<'a> { impl<'a> InsertQuery<'a> { pub fn new( table: &'a Table, - entities: &'a mut [(&'a EntityRef, Cow)], + entities: &'a mut [(&'a EntityKey, Cow)], block: BlockNumber, ) -> Result, StoreError> { for (entity_key, entity) in entities.iter_mut() { @@ -1695,7 +1695,7 @@ impl<'a> InsertQuery<'a> { /// Build the column name list using the subset of all keys among present entities. fn unique_columns( table: &'a Table, - entities: &'a [(&'a EntityRef, Cow<'a, Entity>)], + entities: &'a [(&'a EntityKey, Cow<'a, Entity>)], ) -> Vec<&'a Column> { let mut hashmap = HashMap::new(); for (_key, entity) in entities.iter() { diff --git a/store/postgres/src/writable.rs b/store/postgres/src/writable.rs index 3e9c1b2b19e..2c615d79a87 100644 --- a/store/postgres/src/writable.rs +++ b/store/postgres/src/writable.rs @@ -4,7 +4,7 @@ use std::time::Duration; use std::{collections::BTreeMap, sync::Arc}; use graph::blockchain::block_stream::FirehoseCursor; -use graph::components::store::EntityRef; +use graph::components::store::EntityKey; use graph::data::subgraph::schema; use graph::env::env_var; use graph::prelude::{ @@ -239,7 +239,7 @@ impl SyncStore { .await } - fn get(&self, key: &EntityRef, block: BlockNumber) -> Result, StoreError> { + fn get(&self, key: &EntityKey, block: BlockNumber) -> Result, StoreError> { self.retry("get", || { self.writable.get(self.site.cheap_clone(), key, block) }) @@ -624,7 +624,7 @@ impl Queue { /// Get the entity for `key` if it exists by looking at both the queue /// and the store - fn get(&self, key: &EntityRef) -> Result, StoreError> { + fn get(&self, key: &EntityKey) -> Result, StoreError> { enum Op { Write(Entity), Remove, @@ -864,7 +864,7 @@ impl Writer { } } - fn get(&self, key: &EntityRef) -> Result, StoreError> { + fn get(&self, key: &EntityKey) -> Result, StoreError> { match self { Writer::Sync(store) => store.get(key, BLOCK_NUMBER_MAX), Writer::Async(queue) => queue.get(key), @@ -999,7 +999,7 @@ impl WritableStoreTrait for WritableStore { self.store.supports_proof_of_indexing().await } - fn get(&self, key: &EntityRef) -> Result, StoreError> { + fn get(&self, key: &EntityKey) -> Result, StoreError> { self.writer.get(key) } diff --git a/store/postgres/tests/graft.rs b/store/postgres/tests/graft.rs index 55ec92e2641..df9d9245009 100644 --- a/store/postgres/tests/graft.rs +++ b/store/postgres/tests/graft.rs @@ -5,7 +5,7 @@ use std::{marker::PhantomData, str::FromStr}; use test_store::*; use graph::components::store::{ - DeploymentLocator, EntityOrder, EntityQuery, EntityRef, EntityType, + DeploymentLocator, EntityKey, EntityOrder, EntityQuery, EntityType, }; use graph::data::store::scalar; use graph::data::subgraph::schema::*; @@ -263,7 +263,7 @@ fn create_test_entity( ); EntityOperation::Set { - key: EntityRef { + key: EntityKey { entity_type: EntityType::new(entity_type.to_string()), entity_id: id.into(), }, @@ -329,7 +329,7 @@ async fn check_graft( // Make our own entries for block 2 shaq.set("email", "shaq@gmail.com"); let op = EntityOperation::Set { - key: EntityRef { + key: EntityKey { entity_type: EntityType::new(USER.to_owned()), entity_id: "3".into(), }, diff --git a/store/postgres/tests/relational.rs b/store/postgres/tests/relational.rs index 8f462507d80..cca31b88ef3 100644 --- a/store/postgres/tests/relational.rs +++ b/store/postgres/tests/relational.rs @@ -1,7 +1,7 @@ //! Test mapping of GraphQL schema to a relational schema use diesel::connection::SimpleConnection as _; use diesel::pg::PgConnection; -use graph::components::store::EntityRef; +use graph::components::store::EntityKey; use graph::data::store::scalar; use graph::entity; use graph::prelude::BlockNumber; @@ -218,10 +218,10 @@ fn insert_entity_at( let entities_with_keys_owned = entities .drain(..) .map(|entity| { - let key = EntityRef::data(entity_type.to_owned(), entity.id().unwrap()); + let key = EntityKey::data(entity_type.to_owned(), entity.id().unwrap()); (key, entity) }) - .collect::>(); + .collect::>(); let mut entities_with_keys: Vec<_> = entities_with_keys_owned .iter() .map(|(key, entity)| (key, Cow::from(entity))) @@ -254,10 +254,10 @@ fn update_entity_at( mut entities: Vec, block: BlockNumber, ) { - let entities_with_keys_owned: Vec<(EntityRef, Entity)> = entities + let entities_with_keys_owned: Vec<(EntityKey, Entity)> = entities .drain(..) .map(|entity| { - let key = EntityRef::data(entity_type.to_owned(), entity.id().unwrap()); + let key = EntityKey::data(entity_type.to_owned(), entity.id().unwrap()); (key, entity) }) .collect(); @@ -547,7 +547,7 @@ fn update() { entity.set("string", "updated"); entity.remove("strings"); entity.set("bool", Value::Null); - let key = EntityRef::data("Scalar".to_owned(), entity.id().unwrap().clone()); + let key = EntityKey::data("Scalar".to_owned(), entity.id().unwrap().clone()); let entity_type = EntityType::from("Scalar"); let mut entities = vec![(&key, Cow::from(&entity))]; @@ -594,13 +594,13 @@ fn update_many() { // generate keys let entity_type = EntityType::from("Scalar"); - let keys: Vec = ["one", "two", "three"] + let keys: Vec = ["one", "two", "three"] .iter() - .map(|id| EntityRef::data("Scalar".to_owned(), String::from(*id))) + .map(|id| EntityKey::data("Scalar".to_owned(), String::from(*id))) .collect(); let entities_vec = vec![one, two, three]; - let mut entities: Vec<(&EntityRef, Cow<'_, Entity>)> = keys + let mut entities: Vec<(&EntityKey, Cow<'_, Entity>)> = keys .iter() .zip(entities_vec.iter().map(|e| Cow::Borrowed(e))) .collect(); @@ -666,7 +666,7 @@ fn serialize_bigdecimal() { let d = BigDecimal::from_str(d).unwrap(); entity.set("bigDecimal", d); - let key = EntityRef::data("Scalar".to_owned(), entity.id().unwrap().clone()); + let key = EntityKey::data("Scalar".to_owned(), entity.id().unwrap().clone()); let entity_type = EntityType::from("Scalar"); let mut entities = vec![(&key, Cow::Borrowed(&entity))]; layout @@ -722,7 +722,7 @@ fn delete() { insert_entity(&conn, &layout, "Scalar", vec![two]); // Delete where nothing is getting deleted - let key = EntityRef::data("Scalar".to_owned(), "no such entity".to_owned()); + let key = EntityKey::data("Scalar".to_owned(), "no such entity".to_owned()); let entity_type = EntityType::from("Scalar"); let mut entity_keys = vec![key.entity_id.as_str()]; let count = layout diff --git a/store/postgres/tests/relational_bytes.rs b/store/postgres/tests/relational_bytes.rs index ab0e8826252..56fe6eb3f4d 100644 --- a/store/postgres/tests/relational_bytes.rs +++ b/store/postgres/tests/relational_bytes.rs @@ -1,7 +1,7 @@ //! Test relational schemas that use `Bytes` to store ids use diesel::connection::SimpleConnection as _; use diesel::pg::PgConnection; -use graph::components::store::EntityRef; +use graph::components::store::EntityKey; use graph::data::store::scalar; use graph_mock::MockMetricsRegistry; use hex_literal::hex; @@ -87,7 +87,7 @@ fn remove_test_data(conn: &PgConnection) { } fn insert_entity(conn: &PgConnection, layout: &Layout, entity_type: &str, entity: Entity) { - let key = EntityRef::data(entity_type.to_owned(), entity.id().unwrap()); + let key = EntityKey::data(entity_type.to_owned(), entity.id().unwrap()); let entity_type = EntityType::from(entity_type); let mut entities = vec![(&key, Cow::from(&entity))]; @@ -282,7 +282,7 @@ fn update() { // Update the entity let mut entity = BEEF_ENTITY.clone(); entity.set("name", "Moo"); - let key = EntityRef::data("Thing".to_owned(), entity.id().unwrap().clone()); + let key = EntityKey::data("Thing".to_owned(), entity.id().unwrap().clone()); let entity_id = entity.id().unwrap().clone(); let entity_type = key.entity_type.clone(); @@ -311,7 +311,7 @@ fn delete() { insert_entity(&conn, &layout, "Thing", two); // Delete where nothing is getting deleted - let key = EntityRef::data("Thing".to_owned(), "ffff".to_owned()); + let key = EntityKey::data("Thing".to_owned(), "ffff".to_owned()); let entity_type = key.entity_type.clone(); let mut entity_keys = vec![key.entity_id.as_str()]; let count = layout diff --git a/store/postgres/tests/store.rs b/store/postgres/tests/store.rs index 7fca81e026a..66c60f47c5d 100644 --- a/store/postgres/tests/store.rs +++ b/store/postgres/tests/store.rs @@ -10,7 +10,7 @@ use std::{collections::HashSet, sync::Mutex}; use std::{marker::PhantomData, str::FromStr}; use test_store::*; -use graph::components::store::{DeploymentLocator, EntityRef, WritableStore}; +use graph::components::store::{DeploymentLocator, EntityKey, WritableStore}; use graph::data::subgraph::*; use graph::prelude::*; use graph::{ @@ -287,7 +287,7 @@ fn create_test_entity( ); EntityOperation::Set { - key: EntityRef::data(entity_type.to_owned(), id.to_owned()), + key: EntityKey::data(entity_type.to_owned(), id.to_owned()), data: test_entity, } } @@ -310,7 +310,7 @@ fn get_entity_count(store: Arc, subgraph_id: &DeploymentHash) -> u6 #[test] fn delete_entity() { run_test(|store, writable, deployment| async move { - let entity_key = EntityRef::data(USER.to_owned(), "3".to_owned()); + let entity_key = EntityKey::data(USER.to_owned(), "3".to_owned()); // Check that there is an entity to remove. writable.get(&entity_key).unwrap().unwrap(); @@ -340,7 +340,7 @@ fn delete_entity() { #[test] fn get_entity_1() { run_test(|_, writable, _| async move { - let key = EntityRef::data(USER.to_owned(), "1".to_owned()); + let key = EntityKey::data(USER.to_owned(), "1".to_owned()); let result = writable.get(&key).unwrap(); let mut expected_entity = Entity::new(); @@ -370,7 +370,7 @@ fn get_entity_1() { #[test] fn get_entity_3() { run_test(|_, writable, _| async move { - let key = EntityRef::data(USER.to_owned(), "3".to_owned()); + let key = EntityKey::data(USER.to_owned(), "3".to_owned()); let result = writable.get(&key).unwrap(); let mut expected_entity = Entity::new(); @@ -399,7 +399,7 @@ fn get_entity_3() { #[test] fn insert_entity() { run_test(|store, writable, deployment| async move { - let entity_key = EntityRef::data(USER.to_owned(), "7".to_owned()); + let entity_key = EntityKey::data(USER.to_owned(), "7".to_owned()); let test_entity = create_test_entity( "7", USER, @@ -429,7 +429,7 @@ fn insert_entity() { #[test] fn update_existing() { run_test(|store, writable, deployment| async move { - let entity_key = EntityRef::data(USER.to_owned(), "1".to_owned()); + let entity_key = EntityKey::data(USER.to_owned(), "1".to_owned()); let op = create_test_entity( "1", @@ -475,7 +475,7 @@ fn update_existing() { #[test] fn partially_update_existing() { run_test(|store, writable, deployment| async move { - let entity_key = EntityRef::data(USER.to_owned(), "1".to_owned()); + let entity_key = EntityKey::data(USER.to_owned(), "1".to_owned()); let partial_entity = Entity::from(vec![ ("id", Value::from("1")), @@ -1052,7 +1052,7 @@ fn revert_block_with_delete() { .desc("name"); // Delete entity with id=2 - let del_key = EntityRef::data(USER.to_owned(), "2".to_owned()); + let del_key = EntityKey::data(USER.to_owned(), "2".to_owned()); // Process deletion transact_and_wait( @@ -1097,7 +1097,7 @@ fn revert_block_with_delete() { #[test] fn revert_block_with_partial_update() { run_test(|store, writable, deployment| async move { - let entity_key = EntityRef::data(USER.to_owned(), "1".to_owned()); + let entity_key = EntityKey::data(USER.to_owned(), "1".to_owned()); let partial_entity = Entity::from(vec![ ("id", Value::from("1")), @@ -1195,7 +1195,7 @@ fn revert_block_with_dynamic_data_source_operations() { let subgraph_store = store.subgraph_store(); // Create operations to add a user - let user_key = EntityRef::data(USER.to_owned(), "1".to_owned()); + let user_key = EntityKey::data(USER.to_owned(), "1".to_owned()); let partial_entity = Entity::from(vec![ ("id", Value::from("1")), ("name", Value::from("Johnny Boy")), @@ -1338,7 +1338,7 @@ fn entity_changes_are_fired_and_forwarded_to_subscriptions() { added_entities .iter() .map(|(id, data)| EntityOperation::Set { - key: EntityRef::data(USER.to_owned(), id.to_owned()), + key: EntityKey::data(USER.to_owned(), id.to_owned()), data: data.to_owned(), }) .collect(), @@ -1352,13 +1352,13 @@ fn entity_changes_are_fired_and_forwarded_to_subscriptions() { ("name", Value::from("Johnny")), ]); let update_op = EntityOperation::Set { - key: EntityRef::data(USER.to_owned(), "1".to_owned()), + key: EntityKey::data(USER.to_owned(), "1".to_owned()), data: updated_entity.clone(), }; // Delete an entity in the store let delete_op = EntityOperation::Remove { - key: EntityRef::data(USER.to_owned(), "2".to_owned()), + key: EntityKey::data(USER.to_owned(), "2".to_owned()), }; // Commit update & delete ops @@ -1539,7 +1539,7 @@ fn handle_large_string_with_index() { data.set("id", id); data.set(NAME, name); - let key = EntityRef::data(USER.to_owned(), id.to_owned()); + let key = EntityKey::data(USER.to_owned(), id.to_owned()); EntityModification::Insert { key, data } } @@ -1631,7 +1631,7 @@ fn handle_large_bytea_with_index() { data.set("id", id); data.set(NAME, scalar::Bytes::from(name)); - let key = EntityRef::data(USER.to_owned(), id.to_owned()); + let key = EntityKey::data(USER.to_owned(), id.to_owned()); EntityModification::Insert { key, data } } @@ -1835,7 +1835,7 @@ fn window() { entity.set("age", age); entity.set("favorite_color", color); EntityOperation::Set { - key: EntityRef::data(entity_type.to_owned(), id.to_owned()), + key: EntityKey::data(entity_type.to_owned(), id.to_owned()), data: entity, } } diff --git a/store/postgres/tests/writable.rs b/store/postgres/tests/writable.rs index 6c5593a842b..dbe765c9834 100644 --- a/store/postgres/tests/writable.rs +++ b/store/postgres/tests/writable.rs @@ -4,7 +4,7 @@ use lazy_static::lazy_static; use std::marker::PhantomData; use test_store::*; -use graph::components::store::{DeploymentLocator, EntityRef, WritableStore}; +use graph::components::store::{DeploymentLocator, EntityKey, WritableStore}; use graph::data::subgraph::*; use graph::prelude::*; use graph::semver::Version; @@ -102,8 +102,8 @@ fn block_pointer(number: u8) -> BlockPtr { BlockPtr::from((hash, number as BlockNumber)) } -fn count_key(id: &str) -> EntityRef { - EntityRef::data(COUNTER.to_owned(), id.to_owned()) +fn count_key(id: &str) -> EntityKey { + EntityKey::data(COUNTER.to_owned(), id.to_owned()) } async fn insert_count(store: &Arc, deployment: &DeploymentLocator, count: u8) { diff --git a/store/test-store/src/store.rs b/store/test-store/src/store.rs index 8cb35a8c2b8..14b97055c58 100644 --- a/store/test-store/src/store.rs +++ b/store/test-store/src/store.rs @@ -8,7 +8,7 @@ use graph::prelude::{QueryStoreManager as _, SubgraphStore as _, *}; use graph::semver::Version; use graph::{ blockchain::block_stream::FirehoseCursor, blockchain::ChainIdentifier, - components::store::DeploymentLocator, components::store::EntityRef, + components::store::DeploymentLocator, components::store::EntityKey, components::store::EntityType, components::store::StatusStore, components::store::StoredDynamicDataSource, data::subgraph::status, prelude::NodeId, }; @@ -348,7 +348,7 @@ pub async fn insert_entities( let insert_ops = entities .into_iter() .map(|(entity_type, data)| EntityOperation::Set { - key: EntityRef { + key: EntityKey { entity_type: entity_type.to_owned(), entity_id: data.get("id").unwrap().clone().as_string().unwrap().into(), },