Skip to content

Commit 961556b

Browse files
author
Zoran Cvetkov
committed
address review remarks
1 parent 640e7d1 commit 961556b

File tree

7 files changed

+22
-19
lines changed

7 files changed

+22
-19
lines changed

graph/src/components/store/entity_cache.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::anyhow;
1+
use anyhow::{anyhow, bail};
22
use std::borrow::Borrow;
33
use std::collections::HashMap;
44
use std::fmt::{self, Debug};
@@ -17,8 +17,8 @@ use super::{BlockNumber, DerivedEntityQuery, LoadRelatedRequest, StoreError};
1717

1818
pub type EntityLfuCache = LfuCache<EntityKey, Option<Arc<Entity>>>;
1919

20-
// Number of VIDs that are reserved ourside of the generated ones here.
21-
// Currently only 1 for POIs is used, but lets reserve a few more.
20+
// Number of VIDs that are reserved outside of the generated ones here.
21+
// Currently none is used, but lets reserve a few more.
2222
const RESERVED_VIDS: u32 = 100;
2323

2424
/// The scope in which the `EntityCache` should perform a `get` operation
@@ -374,7 +374,9 @@ impl EntityCache {
374374
let mut entity = entity;
375375
let old_vid = entity.set_vid(vid).expect("the vid should be set");
376376
// Make sure that there was no VID previously set for this entity.
377-
assert!(old_vid.is_none());
377+
if old_vid.is_some() {
378+
bail!("VID was already present when set in EntityCache");
379+
}
378380

379381
self.entity_op(key.clone(), EntityOp::Update(entity));
380382

graph/src/data/store/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{
33
derive::CacheWeight,
44
prelude::{lazy_static, q, r, s, CacheWeight, QueryExecutionError},
55
runtime::gas::{Gas, GasSizeOf},
6-
schema::{EntityKey, EntityType},
6+
schema::{input::VID_FIELD, EntityKey, EntityType},
77
util::intern::{self, AtomPool},
88
util::intern::{Error as InternError, NullValue, Object},
99
};
@@ -913,21 +913,21 @@ impl Entity {
913913
/// Return the VID of this entity and if its missing or of a type different than
914914
/// i64 it panics.
915915
pub fn vid(&self) -> i64 {
916-
self.get("vid")
916+
self.get(VID_FIELD)
917917
.expect("the vid is set")
918918
.as_int8()
919919
.expect("the vid is set to a valid value")
920920
}
921921

922922
/// Sets the VID of the entity. The previous one is returned.
923923
pub fn set_vid(&mut self, value: i64) -> Result<Option<Value>, InternError> {
924-
self.0.insert("vid", value.into())
924+
self.0.insert(VID_FIELD, value.into())
925925
}
926926

927927
/// Sets the VID if it's not already set. Should be used only for tests.
928928
#[cfg(debug_assertions)]
929929
pub fn set_vid_if_empty(&mut self) {
930-
let vid = self.get("vid");
930+
let vid = self.get(VID_FIELD);
931931
if vid.is_none() {
932932
let _ = self.set_vid(100).expect("the vid should be set");
933933
}

graph/src/data/subgraph/api_version.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ pub const SPEC_VERSION_1_1_0: Version = Version::new(1, 1, 0);
5454
// Enables eth call declarations and indexed arguments(topics) filtering in manifest
5555
pub const SPEC_VERSION_1_2_0: Version = Version::new(1, 2, 0);
5656

57-
// Enables subgraphs as datasource
58-
// Change the way the VID field is generated. It used to be autoincrement. Now its
59-
// based on block number and the sequence of the entities in a block.
57+
// Enables subgraphs as datasource.
58+
// Changes the way the VID field is generated. It used to be autoincrement. Now its
59+
// based on block number and the order of the entities in a block. The later is
60+
// representing the writting order of all entity types in a subgraph.
6061
pub const SPEC_VERSION_1_3_0: Version = Version::new(1, 3, 0);
6162

6263
// The latest spec version available

graph/src/schema/input/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub(crate) const POI_OBJECT: &str = "Poi$";
3535
const POI_DIGEST: &str = "digest";
3636
/// The name of the PoI attribute for storing the block time
3737
const POI_BLOCK_TIME: &str = "blockTime";
38-
const VID_FIELD: &str = "vid";
38+
pub(crate) const VID_FIELD: &str = "vid";
3939

4040
pub mod kw {
4141
pub const ENTITY: &str = "entity";

graph/src/schema/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub mod ast;
2121
mod entity_key;
2222
mod entity_type;
2323
mod fulltext;
24-
mod input;
24+
pub(crate) mod input;
2525

2626
pub use api::{is_introspection_field, APISchemaError, INTROSPECTION_QUERY_TYPE};
2727

store/postgres/src/relational/ddl.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ impl Table {
116116
Ok(cols)
117117
}
118118

119-
let vid_type = if !self.object.is_object_type() {
120-
"bigserial"
121-
} else {
119+
let vid_type = if self.object.is_object_type() {
122120
"bigint"
121+
} else {
122+
"bigserial"
123123
};
124124

125125
if self.immutable {

store/postgres/src/relational_queries.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use std::string::ToString;
3838
use crate::block_range::{BoundSide, EntityBlockRange};
3939
use crate::relational::{
4040
Column, ColumnType, Layout, SqlName, Table, BYTE_ARRAY_PREFIX_SIZE, PRIMARY_KEY_COLUMN,
41-
STRING_PREFIX_SIZE,
41+
STRING_PREFIX_SIZE, VID_COLUMN,
4242
};
4343
use crate::{
4444
block_range::{
@@ -539,11 +539,11 @@ impl EntityData {
539539
// table column; those will be things like the
540540
// block_range that `select *` pulls in but that we
541541
// don't care about here
542-
if key == "vid" {
542+
if key == VID_COLUMN {
543543
// VID is not in the input schema but we need it, so deserialize it too
544544
match T::Value::from_column_value(&ColumnType::Int8, json) {
545545
Ok(value) if value.is_null() => None,
546-
Ok(value) => Some(Ok((Word::from("vid"), value))),
546+
Ok(value) => Some(Ok((Word::from(VID_COLUMN), value))),
547547
Err(e) => Some(Err(e)),
548548
}
549549
} else if let Some(column) = table.column(&SqlName::verbatim(key)) {

0 commit comments

Comments
 (0)