Skip to content

Commit 330efe3

Browse files
author
Zoran Cvetkov
committed
cleanup
1 parent efe6254 commit 330efe3

File tree

6 files changed

+71
-75
lines changed

6 files changed

+71
-75
lines changed

graph/src/components/store/entity_cache.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -459,16 +459,16 @@ impl EntityCache {
459459
// Entity was created
460460
(None, EntityOp::Update(mut updates))
461461
| (None, EntityOp::Overwrite(mut updates)) => {
462+
let vid = updates.vid;
462463
updates.e.remove_null_fields();
463-
let data = Arc::new(updates);
464-
self.current
465-
.insert(key.clone(), Some(data.e.clone().into()));
464+
let data = Arc::new(updates.e.clone());
465+
self.current.insert(key.clone(), Some(data.cheap_clone()));
466466
Some(Insert {
467467
key,
468-
data: data.e.clone().into(),
468+
data,
469469
block,
470470
end: None,
471-
vid: data.vid,
471+
vid,
472472
})
473473
}
474474
// Entity may have been changed
@@ -493,16 +493,16 @@ impl EntityCache {
493493
}
494494
// Entity was removed and then updated, so it will be overwritten
495495
(Some(current), EntityOp::Overwrite(data)) => {
496-
let data = Arc::new(data);
497-
self.current
498-
.insert(key.clone(), Some(data.e.clone().into()));
499-
if current != data.e.clone().into() {
496+
let vid = data.vid;
497+
let data = Arc::new(data.e.clone());
498+
self.current.insert(key.clone(), Some(data.cheap_clone()));
499+
if current != data {
500500
Some(Overwrite {
501501
key,
502-
data: data.e.clone().into(),
502+
data,
503503
block,
504504
end: None,
505-
vid: data.vid,
505+
vid,
506506
})
507507
} else {
508508
None

graph/src/schema/input/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,9 +1489,9 @@ impl InputSchema {
14891489

14901490
pub fn has_field_with_name(&self, entity_type: &EntityType, field: &str) -> bool {
14911491
// TODO: check if it is needed
1492-
if field == VID {
1493-
return true;
1494-
}
1492+
// if field == VID {
1493+
// return true;
1494+
// }
14951495
let field = self.inner.pool.lookup(field);
14961496

14971497
match field {

store/postgres/src/relational_queries.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use graph::components::store::write::{EntityWrite, RowGroup, WriteChunk};
1616
use graph::components::store::{Child as StoreChild, DerivedEntityQuery};
1717
use graph::data::store::{EntityV, Id, IdType, NULL};
1818
use graph::data::store::{IdList, IdRef, QueryObject};
19-
use graph::data::subgraph::schema::POI_TABLE;
19+
// use graph::data::subgraph::schema::POI_TABLE;
2020
use graph::data::value::{Object, Word};
2121
use graph::data_source::CausalityRegion;
2222
use graph::prelude::{
@@ -2241,7 +2241,8 @@ impl<'a> QueryFragment<Pg> for InsertQuery<'a> {
22412241
let out = &mut out;
22422242
out.unsafe_to_cache_prepared();
22432243

2244-
let not_poi = self.table.name.as_str() != POI_TABLE;
2244+
// let not_poi = self.table.name.as_str() != POI_TABLE;
2245+
let not_poi = !self.table.object.is_poi();
22452246

22462247
// Construct a query
22472248
// insert into schema.table(column, ...)
@@ -4691,7 +4692,8 @@ impl<'a> QueryFragment<Pg> for CopyEntityBatchQuery<'a> {
46914692
fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, Pg>) -> QueryResult<()> {
46924693
out.unsafe_to_cache_prepared();
46934694

4694-
let not_poi = self.dst.name.as_str() != POI_TABLE;
4695+
// let not_poi = self.dst.name.as_str() != POI_TABLE;
4696+
let not_poi = !self.dst.object.is_poi();
46954697

46964698
// Construct a query
46974699
// insert into {dst}({columns})

store/test-store/tests/graph/entity_cache.rs

Lines changed: 45 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ async fn insert_test_data(store: Arc<DieselSubgraphStore>) -> DeploymentLocator
469469

470470
fn create_account_entity(id: &str, name: &str, email: &str, age: i32, vid: i64) -> EntityOperation {
471471
let test_entity =
472-
entity! { LOAD_RELATED_SUBGRAPH => id: id, name: name, email: email, age: age, vid: vid };
472+
entity! { LOAD_RELATED_SUBGRAPH => id: id, name: name, email: email, age: age };
473473

474474
EntityOperation::Set {
475475
key: ACCOUNT_TYPE.parse_key(id).unwrap(),
@@ -479,8 +479,7 @@ fn create_account_entity(id: &str, name: &str, email: &str, age: i32, vid: i64)
479479

480480
fn create_wallet_entity(id: &str, account_id: &Id, balance: i32, vid: i64) -> EntityV {
481481
let account_id = Value::from(account_id.clone());
482-
let e =
483-
entity! { LOAD_RELATED_SUBGRAPH => id: id, account: account_id, balance: balance, vid: vid};
482+
let e = entity! { LOAD_RELATED_SUBGRAPH => id: id, account: account_id, balance: balance};
484483
EntityV::new(e, vid)
485484
}
486485
fn create_wallet_operation(id: &str, account_id: &Id, balance: i32, vid: i64) -> EntityOperation {
@@ -716,53 +715,49 @@ fn check_for_delete_async_related() {
716715
});
717716
}
718717

719-
// #[test]
720-
// fn scoped_get() {
721-
// run_store_test(|mut cache, _store, _deployment, _writable| async move {
722-
// // Key for an existing entity that is in the store
723-
// let account1 = ACCOUNT_TYPE.parse_id("1").unwrap();
724-
// let key1 = WALLET_TYPE.parse_key("1").unwrap();
725-
// let wallet1 = create_wallet_entity("1", &account1, 67, 1);
726-
727-
// // Create a new entity that is not in the store
728-
// let account5 = ACCOUNT_TYPE.parse_id("5").unwrap();
729-
// let wallet5 = create_wallet_entity("5", &account5, 100, 5);
730-
// let key5 = WALLET_TYPE.parse_key("5").unwrap();
731-
// cache
732-
// .set(key5.clone(), EntityV::new(wallet5.clone(), 5))
733-
// .unwrap();
734-
735-
// // For the new entity, we can retrieve it with either scope
736-
// let act5 = cache.get(&key5, GetScope::InBlock).unwrap();
737-
// assert_eq!(Some(&wallet5), act5.as_ref().map(|e| e.as_ref()));
738-
// let act5 = cache.get(&key5, GetScope::Store).unwrap();
739-
// assert_eq!(Some(&wallet5), act5.as_ref().map(|e| e.as_ref()));
740-
741-
// // For an entity in the store, we can not get it `InBlock` but with
742-
// // `Store`
743-
// let act1 = cache.get(&key1, GetScope::InBlock).unwrap();
744-
// assert_eq!(None, act1);
745-
// let act1 = cache.get(&key1, GetScope::Store).unwrap();
746-
// assert_eq!(
747-
// filter_vid(vec![wallet1.clone()]),
748-
// vec![act1.as_ref().map(|e| e.as_ref()).unwrap().clone()]
749-
// );
750-
// // Even after reading from the store, the entity is not visible with
751-
// // `InBlock`
752-
// let act1 = cache.get(&key1, GetScope::InBlock).unwrap();
753-
// assert_eq!(None, act1);
754-
// // But if it gets updated, it becomes visible with either scope
755-
// let mut wallet1 = wallet1;
756-
// wallet1.set("balance", 70).unwrap();
757-
// cache
758-
// .set(key1.clone(), EntityV::new(wallet1.clone(), 1))
759-
// .unwrap();
760-
// let act1 = cache.get(&key1, GetScope::InBlock).unwrap();
761-
// assert_eq!(Some(&wallet1), act1.as_ref().map(|e| e.as_ref()));
762-
// let act1 = cache.get(&key1, GetScope::Store).unwrap();
763-
// assert_eq!(Some(&wallet1), act1.as_ref().map(|e| e.as_ref()));
764-
// })
765-
// }
718+
#[test]
719+
fn scoped_get() {
720+
run_store_test(|mut cache, _store, _deployment, _writable| async move {
721+
// Key for an existing entity that is in the store
722+
let account1 = ACCOUNT_TYPE.parse_id("1").unwrap();
723+
let key1 = WALLET_TYPE.parse_key("1").unwrap();
724+
let wallet1 = create_wallet_entity("1", &account1, 67, 1);
725+
726+
// Create a new entity that is not in the store
727+
let account5 = ACCOUNT_TYPE.parse_id("5").unwrap();
728+
let wallet5 = create_wallet_entity("5", &account5, 100, 5);
729+
let key5 = WALLET_TYPE.parse_key("5").unwrap();
730+
cache.set(key5.clone(), wallet5.clone()).unwrap();
731+
732+
// For the new entity, we can retrieve it with either scope
733+
let act5 = cache.get(&key5, GetScope::InBlock).unwrap();
734+
assert_eq!(Some(&wallet5.e), act5.as_ref().map(|e| e.as_ref()));
735+
let act5 = cache.get(&key5, GetScope::Store).unwrap();
736+
assert_eq!(Some(&wallet5.e), act5.as_ref().map(|e| e.as_ref()));
737+
738+
// For an entity in the store, we can not get it `InBlock` but with
739+
// `Store`
740+
let act1 = cache.get(&key1, GetScope::InBlock).unwrap();
741+
assert_eq!(None, act1);
742+
let act1 = cache.get(&key1, GetScope::Store).unwrap();
743+
assert_eq!(
744+
filter_vid(vec![wallet1.e.clone()]),
745+
vec![act1.as_ref().map(|e| e.as_ref()).unwrap().clone()]
746+
);
747+
// Even after reading from the store, the entity is not visible with
748+
// `InBlock`
749+
let act1 = cache.get(&key1, GetScope::InBlock).unwrap();
750+
assert_eq!(None, act1);
751+
// But if it gets updated, it becomes visible with either scope
752+
let mut wallet1 = wallet1;
753+
wallet1.e.set("balance", 70).unwrap();
754+
cache.set(key1.clone(), wallet1.clone()).unwrap();
755+
let act1 = cache.get(&key1, GetScope::InBlock).unwrap();
756+
assert_eq!(Some(&wallet1.e), act1.as_ref().map(|e| e.as_ref()));
757+
let act1 = cache.get(&key1, GetScope::Store).unwrap();
758+
assert_eq!(Some(&wallet1.e), act1.as_ref().map(|e| e.as_ref()));
759+
})
760+
}
766761

767762
/// Entities should never contain a `__typename` or `g$parent_id` field, if
768763
/// they do, that can cause PoI divergences, because entities will differ

store/test-store/tests/postgres/graft.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ fn create_test_entity(
257257
seconds_age: age * 31557600,
258258
weight: Value::BigDecimal(weight.into()),
259259
coffee: coffee,
260-
favorite_color: favorite_color,
260+
favorite_color: favorite_color
261261
};
262262

263263
let entity_type = TEST_SUBGRAPH_SCHEMA.entity_type(entity_type).unwrap();
@@ -329,10 +329,9 @@ async fn check_graft(
329329

330330
// Make our own entries for block 2
331331
shaq.set("email", "[email protected]").unwrap();
332-
// shaq.set("vid", 5i64).unwrap();
333332
let op = EntityOperation::Set {
334333
key: user_type.parse_key("3").unwrap(),
335-
data: EntityV::new(shaq, 5),
334+
data: EntityV::new(shaq, 3),
336335
};
337336
transact_and_wait(&store, &deployment, BLOCKS[2].clone(), vec![op])
338337
.await

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,7 +1522,7 @@ fn handle_large_string_with_index() {
15221522
block: BlockNumber,
15231523
vid: i64,
15241524
) -> EntityModification {
1525-
let data = entity! { schema => id: id, name: name, vid: vid };
1525+
let data = entity! { schema => id: id, name: name };
15261526

15271527
let key = USER_TYPE.parse_key(id).unwrap();
15281528

@@ -1622,7 +1622,7 @@ fn handle_large_bytea_with_index() {
16221622
block: BlockNumber,
16231623
vid: i64,
16241624
) -> EntityModification {
1625-
let data = entity! { schema => id: id, bin_name: scalar::Bytes::from(name), vid: vid };
1625+
let data = entity! { schema => id: id, bin_name: scalar::Bytes::from(name) };
16261626

16271627
let key = USER_TYPE.parse_key(id).unwrap();
16281628

@@ -2157,15 +2157,15 @@ fn reorg_tracking() {
21572157
check_state!(store, 2, 2, 2);
21582158

21592159
// Forward to block 3
2160-
update_john(&subgraph_store, &deployment, 70, &TEST_BLOCK_3_PTR, 30).await;
2160+
update_john(&subgraph_store, &deployment, 70, &TEST_BLOCK_3_PTR, 5).await;
21612161
check_state!(store, 2, 2, 3);
21622162

21632163
// Forward to block 4
2164-
update_john(&subgraph_store, &deployment, 71, &TEST_BLOCK_4_PTR, 40).await;
2164+
update_john(&subgraph_store, &deployment, 71, &TEST_BLOCK_4_PTR, 6).await;
21652165
check_state!(store, 2, 2, 4);
21662166

21672167
// Forward to block 5
2168-
update_john(&subgraph_store, &deployment, 72, &TEST_BLOCK_5_PTR, 50).await;
2168+
update_john(&subgraph_store, &deployment, 72, &TEST_BLOCK_5_PTR, 7).await;
21692169
check_state!(store, 2, 2, 5);
21702170

21712171
// Revert all the way back to block 2

0 commit comments

Comments
 (0)