Skip to content

Commit

Permalink
store: Implement block_ptr_with_conn properly
Browse files Browse the repository at this point in the history
  • Loading branch information
leoyvens committed Oct 29, 2019
1 parent b7e5424 commit 777f784
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
15 changes: 15 additions & 0 deletions store/postgres/src/entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,21 @@ impl Connection {
}
}

pub(crate) fn find_metadata(
&self,
entity: &String,
id: &String,
) -> Result<Option<Entity>, StoreError> {
use self::subgraphs::entities;
entities::dsl::entities
.filter(entities::entity.eq(entity).and(entities::id.eq(id)))
.select(entities::data)
.first::<serde_json::Value>(&self.conn)
.optional()?
.map(|json| entity_from_json(json, entity))
.transpose()
}

pub(crate) fn delete(
&self,
key: &EntityKey,
Expand Down
6 changes: 3 additions & 3 deletions store/postgres/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,8 +727,8 @@ impl Store {
conn: &e::Connection,
) -> Result<EthereumBlockPointer, Error> {
let key = SubgraphDeploymentEntity::key(subgraph_id.clone());
let subgraph_entity = self
.get_entity(&conn, &key.subgraph_id, &key.entity_type, &key.entity_id)
let subgraph_entity = conn
.find_metadata(&key.entity_type, &key.entity_id)
.map_err(|e| format_err!("error reading subgraph entity: {}", e))?
.ok_or_else(|| {
format_err!(
Expand Down Expand Up @@ -844,7 +844,7 @@ impl StoreTrait for Store {

let (event, metadata_event, should_migrate) =
econn.transaction(|| -> Result<_, StoreError> {
let block_ptr_from = self.block_ptr(subgraph_id.clone())?;
let block_ptr_from = self.block_ptr_with_conn(subgraph_id.clone(), &econn)?;
assert!(block_ptr_from.number < block_ptr_to.number);

// Ensure the history event exists in the database
Expand Down

0 comments on commit 777f784

Please sign in to comment.