@@ -553,7 +553,7 @@ impl<'a> FromIterator<&'a EntityModification> for StoreEvent {
553553 . map ( |op| {
554554 use self :: EntityModification :: * ;
555555 match op {
556- Insert { key, .. } | Overwrite { key, .. } | Remove { key, .. } => {
556+ Insert { key, .. } | Overwrite { key, .. } | Remove { key } => {
557557 EntityChange :: for_data ( key. clone ( ) )
558558 }
559559 }
@@ -1034,7 +1034,7 @@ pub trait WritableStore: Send + Sync + 'static {
10341034 async fn supports_proof_of_indexing ( & self ) -> Result < bool , StoreError > ;
10351035
10361036 /// Looks up an entity using the given store key at the latest block.
1037- fn get ( & self , key : & EntityKey ) -> Result < Option < EntityVersion > , StoreError > ;
1037+ fn get ( & self , key : & EntityKey ) -> Result < Option < Entity > , StoreError > ;
10381038
10391039 /// Transact the entity changes from a single block atomically into the store, and update the
10401040 /// subgraph block pointer to `block_ptr_to`, and update the firehose cursor to `firehose_cursor`
@@ -1048,14 +1048,14 @@ pub trait WritableStore: Send + Sync + 'static {
10481048 stopwatch : StopwatchMetrics ,
10491049 data_sources : Vec < StoredDynamicDataSource > ,
10501050 deterministic_errors : Vec < SubgraphError > ,
1051- ) -> Result < Vec < ( EntityKey , Vid ) > , StoreError > ;
1051+ ) -> Result < ( ) , StoreError > ;
10521052
10531053 /// Look up multiple entities as of the latest block. Returns a map of
10541054 /// entities by type.
10551055 fn get_many (
10561056 & self ,
10571057 ids_for_type : BTreeMap < & EntityType , Vec < & str > > ,
1058- ) -> Result < BTreeMap < EntityType , Vec < EntityVersion > > , StoreError > ;
1058+ ) -> Result < BTreeMap < EntityType , Vec < Entity > > , StoreError > ;
10591059
10601060 /// The deployment `id` finished syncing, mark it as synced in the database
10611061 /// and promote it to the current version in the subgraphs where it was the
@@ -1101,7 +1101,7 @@ mock! {
11011101 fn get_many_mock<' a>(
11021102 & self ,
11031103 _ids_for_type: BTreeMap <& ' a EntityType , Vec <& ' a str >>,
1104- ) -> Result <BTreeMap <EntityType , Vec <EntityVersion >>, StoreError >;
1104+ ) -> Result <BTreeMap <EntityType , Vec <Entity >>, StoreError >;
11051105 }
11061106}
11071107
@@ -1224,7 +1224,7 @@ impl WritableStore for MockStore {
12241224 unimplemented ! ( )
12251225 }
12261226
1227- fn get ( & self , _: & EntityKey ) -> Result < Option < EntityVersion > , StoreError > {
1227+ fn get ( & self , _: & EntityKey ) -> Result < Option < Entity > , StoreError > {
12281228 unimplemented ! ( )
12291229 }
12301230
@@ -1236,14 +1236,14 @@ impl WritableStore for MockStore {
12361236 _: StopwatchMetrics ,
12371237 _: Vec < StoredDynamicDataSource > ,
12381238 _: Vec < SubgraphError > ,
1239- ) -> Result < Vec < ( EntityKey , Vid ) > , StoreError > {
1239+ ) -> Result < ( ) , StoreError > {
12401240 unimplemented ! ( )
12411241 }
12421242
12431243 fn get_many (
12441244 & self ,
12451245 ids_for_type : BTreeMap < & EntityType , Vec < & str > > ,
1246- ) -> Result < BTreeMap < EntityType , Vec < EntityVersion > > , StoreError > {
1246+ ) -> Result < BTreeMap < EntityType , Vec < Entity > > , StoreError > {
12471247 self . get_many_mock ( ids_for_type)
12481248 }
12491249
@@ -1457,20 +1457,16 @@ pub enum EntityModification {
14571457 /// Insert the entity
14581458 Insert { key : EntityKey , data : Entity } ,
14591459 /// Update the entity by overwriting it
1460- Overwrite {
1461- key : EntityKey ,
1462- data : Entity ,
1463- prev_vid : Vid ,
1464- } ,
1460+ Overwrite { key : EntityKey , data : Entity } ,
14651461 /// Remove the entity
1466- Remove { key : EntityKey , prev_vid : Vid } ,
1462+ Remove { key : EntityKey } ,
14671463}
14681464
14691465impl EntityModification {
14701466 pub fn entity_key ( & self ) -> & EntityKey {
14711467 use EntityModification :: * ;
14721468 match self {
1473- Insert { key, .. } | Overwrite { key, .. } | Remove { key, .. } => key,
1469+ Insert { key, .. } | Overwrite { key, .. } | Remove { key } => key,
14741470 }
14751471 }
14761472
@@ -1533,7 +1529,7 @@ impl EntityOp {
15331529pub struct EntityCache {
15341530 /// The state of entities in the store. An entry of `None`
15351531 /// means that the entity is not present in the store
1536- current : LfuCache < EntityKey , Option < EntityVersion > > ,
1532+ current : LfuCache < EntityKey , Option < Entity > > ,
15371533
15381534 /// The accumulated changes to an entity.
15391535 updates : HashMap < EntityKey , EntityOp > ,
@@ -1562,7 +1558,7 @@ impl Debug for EntityCache {
15621558pub struct ModificationsAndCache {
15631559 pub modifications : Vec < EntityModification > ,
15641560 pub data_sources : Vec < StoredDynamicDataSource > ,
1565- pub entity_lfu_cache : LfuCache < EntityKey , Option < EntityVersion > > ,
1561+ pub entity_lfu_cache : LfuCache < EntityKey , Option < Entity > > ,
15661562}
15671563
15681564impl EntityCache {
@@ -1579,7 +1575,7 @@ impl EntityCache {
15791575
15801576 pub fn with_current (
15811577 store : Arc < dyn WritableStore > ,
1582- current : LfuCache < EntityKey , Option < EntityVersion > > ,
1578+ current : LfuCache < EntityKey , Option < Entity > > ,
15831579 ) -> EntityCache {
15841580 EntityCache {
15851581 current,
@@ -1615,10 +1611,7 @@ impl EntityCache {
16151611
16161612 pub fn get ( & mut self , key : & EntityKey ) -> Result < Option < Entity > , QueryExecutionError > {
16171613 // Get the current entity, apply any updates from `updates`, then from `handler_updates`.
1618- let mut entity = self
1619- . current
1620- . get_entity ( & * self . store , key) ?
1621- . map ( |ev| ev. data ) ;
1614+ let mut entity = self . current . get_entity ( & * self . store , key) ?;
16221615 if let Some ( op) = self . updates . get ( key) . cloned ( ) {
16231616 entity = op. apply_to ( entity)
16241617 }
@@ -1708,14 +1701,14 @@ impl EntityCache {
17081701 }
17091702
17101703 for ( subgraph_id, keys) in missing_by_subgraph {
1711- for ( entity_type, evs ) in self . store . get_many ( keys) ? {
1712- for ev in evs {
1704+ for ( entity_type, entities ) in self . store . get_many ( keys) ? {
1705+ for entity in entities {
17131706 let key = EntityKey {
17141707 subgraph_id : subgraph_id. clone ( ) ,
17151708 entity_type : entity_type. clone ( ) ,
1716- entity_id : ev . data . id ( ) . unwrap ( ) ,
1709+ entity_id : entity . id ( ) . unwrap ( ) ,
17171710 } ;
1718- self . current . insert ( key, Some ( ev ) ) ;
1711+ self . current . insert ( key, Some ( entity ) ) ;
17191712 }
17201713 }
17211714 }
@@ -1730,47 +1723,33 @@ impl EntityCache {
17301723 // Merging with an empty entity removes null fields.
17311724 let mut data = Entity :: new ( ) ;
17321725 data. merge_remove_null_fields ( updates) ;
1733- let ev = EntityVersion :: new ( data. clone ( ) , None ) ;
1734- self . current . insert ( key. clone ( ) , Some ( ev) ) ;
1726+ self . current . insert ( key. clone ( ) , Some ( data. clone ( ) ) ) ;
17351727 Some ( Insert { key, data } )
17361728 }
17371729 // Entity may have been changed
17381730 ( Some ( current) , EntityOp :: Update ( updates) ) => {
1739- let mut data = current. data . clone ( ) ;
1731+ let mut data = current. clone ( ) ;
17401732 data. merge_remove_null_fields ( updates) ;
1741- let ev = EntityVersion :: new ( data. clone ( ) , current. vid ) ;
1742- self . current . insert ( key. clone ( ) , Some ( ev) ) ;
1743- if current. data != data {
1744- Some ( Overwrite {
1745- key,
1746- data,
1747- prev_vid : current. vid ,
1748- } )
1733+ self . current . insert ( key. clone ( ) , Some ( data. clone ( ) ) ) ;
1734+ if current != data {
1735+ Some ( Overwrite { key, data } )
17491736 } else {
17501737 None
17511738 }
17521739 }
17531740 // Entity was removed and then updated, so it will be overwritten
17541741 ( Some ( current) , EntityOp :: Overwrite ( data) ) => {
1755- let ev = EntityVersion :: new ( data. clone ( ) , current. vid ) ;
1756- self . current . insert ( key. clone ( ) , Some ( ev) ) ;
1757- if current. data != data {
1758- Some ( Overwrite {
1759- key,
1760- data,
1761- prev_vid : current. vid ,
1762- } )
1742+ self . current . insert ( key. clone ( ) , Some ( data. clone ( ) ) ) ;
1743+ if current != data {
1744+ Some ( Overwrite { key, data } )
17631745 } else {
17641746 None
17651747 }
17661748 }
17671749 // Existing entity was deleted
1768- ( Some ( current ) , EntityOp :: Remove ) => {
1750+ ( Some ( _ ) , EntityOp :: Remove ) => {
17691751 self . current . insert ( key. clone ( ) , None ) ;
1770- Some ( Remove {
1771- key,
1772- prev_vid : current. vid ,
1773- } )
1752+ Some ( Remove { key } )
17741753 }
17751754 // Entity was deleted, but it doesn't exist in the store
17761755 ( None , EntityOp :: Remove ) => None ,
@@ -1787,39 +1766,26 @@ impl EntityCache {
17871766 }
17881767}
17891768
1790- impl LfuCache < EntityKey , Option < EntityVersion > > {
1769+ impl LfuCache < EntityKey , Option < Entity > > {
17911770 // Helper for cached lookup of an entity.
17921771 fn get_entity (
17931772 & mut self ,
17941773 store : & ( impl WritableStore + ?Sized ) ,
17951774 key : & EntityKey ,
1796- ) -> Result < Option < EntityVersion > , QueryExecutionError > {
1775+ ) -> Result < Option < Entity > , QueryExecutionError > {
17971776 match self . get ( key) {
17981777 None => {
17991778 let mut entity = store. get ( key) ?;
18001779 if let Some ( entity) = & mut entity {
18011780 // `__typename` is for queries not for mappings.
1802- entity. data . remove ( "__typename" ) ;
1781+ entity. remove ( "__typename" ) ;
18031782 }
18041783 self . insert ( key. clone ( ) , entity. clone ( ) ) ;
18051784 Ok ( entity)
18061785 }
18071786 Some ( data) => Ok ( data. to_owned ( ) ) ,
18081787 }
18091788 }
1810-
1811- /// Update the `vid` of cached entities to reflect changes made in the
1812- /// database. When entities stay cached across insert/update operations,
1813- /// their vid in the database changes as a result of these operations
1814- /// and needs to be updated
1815- pub fn update_vids ( & mut self , vid_map : Vec < ( EntityKey , Vid ) > ) {
1816- for ( key, vid) in vid_map {
1817- assert ! ( vid. is_some( ) ) ;
1818- if let Some ( Some ( x) ) = self . get_mut ( key) {
1819- x. vid = vid;
1820- }
1821- }
1822- }
18231789}
18241790
18251791/// Determines which columns should be selected in a table.
0 commit comments