Skip to content

Commit b858ab3

Browse files
committed
.
1 parent 0f37fc5 commit b858ab3

File tree

1 file changed

+36
-37
lines changed

1 file changed

+36
-37
lines changed

shared/src/sync_engine/optimistic/db/object_store.rs

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ where
5151
S: Store + 'static,
5252
Mode: TxnMode<SupportsReadOnly = Present>,
5353
{
54-
pub async fn get_optimistically(&self, id: &S::Id) -> Result<Option<MaybeOptimistic<S>>, Error> {
54+
pub async fn get_optimistically(
55+
&self,
56+
id: &S::Id,
57+
) -> Result<Option<MaybeOptimistic<S>>, Error> {
5558
self.reactivity_trackers
5659
.borrow_mut()
5760
.add_by_id_read(S::NAME, SerializedId::new_from_id::<S>(id));
@@ -156,16 +159,17 @@ where
156159
.map_err(|e| Error::new(e, self.location))?;
157160
self.optimistic_changes.remove_successful_for_id::<S>(id);
158161

159-
if let Some(commit_listener) = self.commit_listener.as_ref() {
160-
let reactivity_trackers = ReactivityTrackers {
161-
stores_modified: hashmap![S::NAME => hashset![SerializedId::new_from_id::<S>(id)]],
162-
..Default::default()
163-
};
164-
tracing::trace!(
165-
"In ObjectStoreWithOptimisticChanges::delete calling commit listener with {:?}",
166-
reactivity_trackers
167-
);
168-
commit_listener(&reactivity_trackers);
162+
let serialized_id = SerializedId::new_from_id::<S>(id);
163+
let optimistic_id = self
164+
.optimistic_changes
165+
.get_realistic_to_optimistic_for_creations()
166+
.get(&serialized_id)
167+
.map(|i| i.clone());
168+
169+
let mut reactivity_trackers = self.reactivity_trackers.borrow_mut();
170+
reactivity_trackers.add_modification(S::NAME, serialized_id);
171+
if let Some(optimistic_id) = optimistic_id {
172+
reactivity_trackers.add_modification(S::NAME, optimistic_id);
169173
}
170174

171175
Ok(())
@@ -179,36 +183,27 @@ where
179183
self.optimistic_changes
180184
.remove_successful_for_id::<S>(item.id());
181185

182-
if let Some(commit_listener) = self.commit_listener.as_ref() {
183-
let optimistic_id = self
184-
.optimistic_changes
185-
.get_realistic_to_optimistic_for_creations()
186-
.get(&SerializedId::new_from_id::<S>(item.id()))
187-
.map(|i| i.clone());
188-
189-
let reactivity_trackers = ReactivityTrackers {
190-
stores_modified: hashmap![
191-
S::NAME => [
192-
Some(SerializedId::new_from_row(item)),
193-
optimistic_id,
194-
]
195-
.into_iter()
196-
.filter_map(|i| i)
197-
.collect(),
198-
],
199-
..Default::default()
200-
};
201-
tracing::trace!(
202-
"In ObjectStoreWithOptimisticChanges::put calling commit listener with {:?}",
203-
reactivity_trackers
204-
);
205-
commit_listener(&reactivity_trackers);
186+
let serialized_id = SerializedId::new_from_row(item);
187+
let optimistic_id = self
188+
.optimistic_changes
189+
.get_realistic_to_optimistic_for_creations()
190+
.get(&serialized_id)
191+
.map(|i| i.clone());
192+
193+
let mut reactivity_trackers = self.reactivity_trackers.borrow_mut();
194+
reactivity_trackers.add_modification(S::NAME, serialized_id);
195+
if let Some(optimistic_id) = optimistic_id {
196+
reactivity_trackers.add_modification(S::NAME, optimistic_id);
206197
}
207198

208199
Ok(())
209200
}
210201

211-
pub fn update_optimistically(&self, row: S, update_fut: impl Future<Output = Result<(), ()>> + 'static) {
202+
pub fn update_optimistically(
203+
&self,
204+
row: S,
205+
update_fut: impl Future<Output = Result<(), ()>> + 'static,
206+
) {
212207
let reactivity_trackers = ReactivityTrackers {
213208
stores_modified: hashmap![S::NAME => hashset![SerializedId::new_from_row(&row)]],
214209
..Default::default()
@@ -224,7 +219,11 @@ where
224219
}
225220
}
226221

227-
pub fn create_optimistically(&self, row: S, create_fut: impl Future<Output = Result<S::Id, ()>> + 'static) {
222+
pub fn create_optimistically(
223+
&self,
224+
row: S,
225+
create_fut: impl Future<Output = Result<S::Id, ()>> + 'static,
226+
) {
228227
let reactivity_trackers = ReactivityTrackers {
229228
stores_modified: hashmap![S::NAME => hashset![SerializedId::new_from_row(&row)]],
230229
..Default::default()

0 commit comments

Comments
 (0)