@@ -553,7 +553,7 @@ impl<'a> FromIterator<&'a EntityModification> for StoreEvent {
553
553
. map ( |op| {
554
554
use self :: EntityModification :: * ;
555
555
match op {
556
- Insert { key, .. } | Overwrite { key, .. } | Remove { key, .. } => {
556
+ Insert { key, .. } | Overwrite { key, .. } | Remove { key } => {
557
557
EntityChange :: for_data ( key. clone ( ) )
558
558
}
559
559
}
@@ -1034,7 +1034,7 @@ pub trait WritableStore: Send + Sync + 'static {
1034
1034
async fn supports_proof_of_indexing ( & self ) -> Result < bool , StoreError > ;
1035
1035
1036
1036
/// 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 > ;
1038
1038
1039
1039
/// Transact the entity changes from a single block atomically into the store, and update the
1040
1040
/// 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 {
1048
1048
stopwatch : StopwatchMetrics ,
1049
1049
data_sources : Vec < StoredDynamicDataSource > ,
1050
1050
deterministic_errors : Vec < SubgraphError > ,
1051
- ) -> Result < Vec < ( EntityKey , Vid ) > , StoreError > ;
1051
+ ) -> Result < ( ) , StoreError > ;
1052
1052
1053
1053
/// Look up multiple entities as of the latest block. Returns a map of
1054
1054
/// entities by type.
1055
1055
fn get_many (
1056
1056
& self ,
1057
1057
ids_for_type : BTreeMap < & EntityType , Vec < & str > > ,
1058
- ) -> Result < BTreeMap < EntityType , Vec < EntityVersion > > , StoreError > ;
1058
+ ) -> Result < BTreeMap < EntityType , Vec < Entity > > , StoreError > ;
1059
1059
1060
1060
/// The deployment `id` finished syncing, mark it as synced in the database
1061
1061
/// and promote it to the current version in the subgraphs where it was the
@@ -1101,7 +1101,7 @@ mock! {
1101
1101
fn get_many_mock<' a>(
1102
1102
& self ,
1103
1103
_ids_for_type: BTreeMap <& ' a EntityType , Vec <& ' a str >>,
1104
- ) -> Result <BTreeMap <EntityType , Vec <EntityVersion >>, StoreError >;
1104
+ ) -> Result <BTreeMap <EntityType , Vec <Entity >>, StoreError >;
1105
1105
}
1106
1106
}
1107
1107
@@ -1224,7 +1224,7 @@ impl WritableStore for MockStore {
1224
1224
unimplemented ! ( )
1225
1225
}
1226
1226
1227
- fn get ( & self , _: & EntityKey ) -> Result < Option < EntityVersion > , StoreError > {
1227
+ fn get ( & self , _: & EntityKey ) -> Result < Option < Entity > , StoreError > {
1228
1228
unimplemented ! ( )
1229
1229
}
1230
1230
@@ -1236,14 +1236,14 @@ impl WritableStore for MockStore {
1236
1236
_: StopwatchMetrics ,
1237
1237
_: Vec < StoredDynamicDataSource > ,
1238
1238
_: Vec < SubgraphError > ,
1239
- ) -> Result < Vec < ( EntityKey , Vid ) > , StoreError > {
1239
+ ) -> Result < ( ) , StoreError > {
1240
1240
unimplemented ! ( )
1241
1241
}
1242
1242
1243
1243
fn get_many (
1244
1244
& self ,
1245
1245
ids_for_type : BTreeMap < & EntityType , Vec < & str > > ,
1246
- ) -> Result < BTreeMap < EntityType , Vec < EntityVersion > > , StoreError > {
1246
+ ) -> Result < BTreeMap < EntityType , Vec < Entity > > , StoreError > {
1247
1247
self . get_many_mock ( ids_for_type)
1248
1248
}
1249
1249
@@ -1457,20 +1457,16 @@ pub enum EntityModification {
1457
1457
/// Insert the entity
1458
1458
Insert { key : EntityKey , data : Entity } ,
1459
1459
/// 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 } ,
1465
1461
/// Remove the entity
1466
- Remove { key : EntityKey , prev_vid : Vid } ,
1462
+ Remove { key : EntityKey } ,
1467
1463
}
1468
1464
1469
1465
impl EntityModification {
1470
1466
pub fn entity_key ( & self ) -> & EntityKey {
1471
1467
use EntityModification :: * ;
1472
1468
match self {
1473
- Insert { key, .. } | Overwrite { key, .. } | Remove { key, .. } => key,
1469
+ Insert { key, .. } | Overwrite { key, .. } | Remove { key } => key,
1474
1470
}
1475
1471
}
1476
1472
@@ -1533,7 +1529,7 @@ impl EntityOp {
1533
1529
pub struct EntityCache {
1534
1530
/// The state of entities in the store. An entry of `None`
1535
1531
/// means that the entity is not present in the store
1536
- current : LfuCache < EntityKey , Option < EntityVersion > > ,
1532
+ current : LfuCache < EntityKey , Option < Entity > > ,
1537
1533
1538
1534
/// The accumulated changes to an entity.
1539
1535
updates : HashMap < EntityKey , EntityOp > ,
@@ -1562,7 +1558,7 @@ impl Debug for EntityCache {
1562
1558
pub struct ModificationsAndCache {
1563
1559
pub modifications : Vec < EntityModification > ,
1564
1560
pub data_sources : Vec < StoredDynamicDataSource > ,
1565
- pub entity_lfu_cache : LfuCache < EntityKey , Option < EntityVersion > > ,
1561
+ pub entity_lfu_cache : LfuCache < EntityKey , Option < Entity > > ,
1566
1562
}
1567
1563
1568
1564
impl EntityCache {
@@ -1579,7 +1575,7 @@ impl EntityCache {
1579
1575
1580
1576
pub fn with_current (
1581
1577
store : Arc < dyn WritableStore > ,
1582
- current : LfuCache < EntityKey , Option < EntityVersion > > ,
1578
+ current : LfuCache < EntityKey , Option < Entity > > ,
1583
1579
) -> EntityCache {
1584
1580
EntityCache {
1585
1581
current,
@@ -1615,10 +1611,7 @@ impl EntityCache {
1615
1611
1616
1612
pub fn get ( & mut self , key : & EntityKey ) -> Result < Option < Entity > , QueryExecutionError > {
1617
1613
// 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) ?;
1622
1615
if let Some ( op) = self . updates . get ( key) . cloned ( ) {
1623
1616
entity = op. apply_to ( entity)
1624
1617
}
@@ -1708,14 +1701,14 @@ impl EntityCache {
1708
1701
}
1709
1702
1710
1703
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 {
1713
1706
let key = EntityKey {
1714
1707
subgraph_id : subgraph_id. clone ( ) ,
1715
1708
entity_type : entity_type. clone ( ) ,
1716
- entity_id : ev . data . id ( ) . unwrap ( ) ,
1709
+ entity_id : entity . id ( ) . unwrap ( ) ,
1717
1710
} ;
1718
- self . current . insert ( key, Some ( ev ) ) ;
1711
+ self . current . insert ( key, Some ( entity ) ) ;
1719
1712
}
1720
1713
}
1721
1714
}
@@ -1730,47 +1723,33 @@ impl EntityCache {
1730
1723
// Merging with an empty entity removes null fields.
1731
1724
let mut data = Entity :: new ( ) ;
1732
1725
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 ( ) ) ) ;
1735
1727
Some ( Insert { key, data } )
1736
1728
}
1737
1729
// Entity may have been changed
1738
1730
( Some ( current) , EntityOp :: Update ( updates) ) => {
1739
- let mut data = current. data . clone ( ) ;
1731
+ let mut data = current. clone ( ) ;
1740
1732
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 } )
1749
1736
} else {
1750
1737
None
1751
1738
}
1752
1739
}
1753
1740
// Entity was removed and then updated, so it will be overwritten
1754
1741
( 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 } )
1763
1745
} else {
1764
1746
None
1765
1747
}
1766
1748
}
1767
1749
// Existing entity was deleted
1768
- ( Some ( current ) , EntityOp :: Remove ) => {
1750
+ ( Some ( _ ) , EntityOp :: Remove ) => {
1769
1751
self . current . insert ( key. clone ( ) , None ) ;
1770
- Some ( Remove {
1771
- key,
1772
- prev_vid : current. vid ,
1773
- } )
1752
+ Some ( Remove { key } )
1774
1753
}
1775
1754
// Entity was deleted, but it doesn't exist in the store
1776
1755
( None , EntityOp :: Remove ) => None ,
@@ -1787,39 +1766,26 @@ impl EntityCache {
1787
1766
}
1788
1767
}
1789
1768
1790
- impl LfuCache < EntityKey , Option < EntityVersion > > {
1769
+ impl LfuCache < EntityKey , Option < Entity > > {
1791
1770
// Helper for cached lookup of an entity.
1792
1771
fn get_entity (
1793
1772
& mut self ,
1794
1773
store : & ( impl WritableStore + ?Sized ) ,
1795
1774
key : & EntityKey ,
1796
- ) -> Result < Option < EntityVersion > , QueryExecutionError > {
1775
+ ) -> Result < Option < Entity > , QueryExecutionError > {
1797
1776
match self . get ( key) {
1798
1777
None => {
1799
1778
let mut entity = store. get ( key) ?;
1800
1779
if let Some ( entity) = & mut entity {
1801
1780
// `__typename` is for queries not for mappings.
1802
- entity. data . remove ( "__typename" ) ;
1781
+ entity. remove ( "__typename" ) ;
1803
1782
}
1804
1783
self . insert ( key. clone ( ) , entity. clone ( ) ) ;
1805
1784
Ok ( entity)
1806
1785
}
1807
1786
Some ( data) => Ok ( data. to_owned ( ) ) ,
1808
1787
}
1809
1788
}
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
- }
1823
1789
}
1824
1790
1825
1791
/// Determines which columns should be selected in a table.
0 commit comments