Skip to content

Commit 0f37fc5

Browse files
committed
get->get_opimistically, get_no_optimism->get and so on
1 parent e45af23 commit 0f37fc5

File tree

18 files changed

+73
-62
lines changed

18 files changed

+73
-62
lines changed

shared/src/sync_engine/changes.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ where
470470
for (_, issue) in issues {
471471
match issue {
472472
ExistingOrDeleted::Existing(issue) => {
473-
let existing = issue_store.no_optimism_get(&issue.id).await?;
473+
let existing = issue_store.get(&issue.id).await?;
474474
let merged = match existing {
475475
Some(existing) => existing.with_merged(issue)?,
476476
None => issue,
@@ -499,7 +499,7 @@ where
499499
match issue_comment {
500500
ExistingOrDeleted::Existing(issue_comment) => {
501501
let existing = issue_comment_store
502-
.no_optimism_get(&issue_comment.id)
502+
.get(&issue_comment.id)
503503
.await?;
504504
let merged = match existing {
505505
Some(existing) => existing.with_merged(issue_comment)?,
@@ -527,7 +527,7 @@ where
527527
for (_, github_app) in github_apps {
528528
match github_app {
529529
ExistingOrDeleted::Existing(github_app) => {
530-
let existing = github_app_store.no_optimism_get(&github_app.id).await?;
530+
let existing = github_app_store.get(&github_app.id).await?;
531531
let merged = match existing {
532532
Some(existing) => existing.with_merged(github_app)?,
533533
None => github_app,
@@ -554,7 +554,7 @@ where
554554
for (_, user) in users {
555555
match user {
556556
ExistingOrDeleted::Existing(user) => {
557-
let existing = user_store.no_optimism_get(&user.id).await?;
557+
let existing = user_store.get(&user.id).await?;
558558
let merged = match existing {
559559
Some(existing) => existing.with_merged(user)?,
560560
None => user,
@@ -582,7 +582,7 @@ where
582582
for (_, license) in licenses {
583583
match license {
584584
ExistingOrDeleted::Existing(license) => {
585-
let existing = license_store.no_optimism_get(&license.key).await?;
585+
let existing = license_store.get(&license.key).await?;
586586
let merged = match existing {
587587
Some(existing) => existing.with_merged(license)?,
588588
None => license,
@@ -610,7 +610,7 @@ where
610610
for (_, milestone) in milestones {
611611
match milestone {
612612
ExistingOrDeleted::Existing(milestone) => {
613-
let existing = milestone_store.no_optimism_get(&milestone.id).await?;
613+
let existing = milestone_store.get(&milestone.id).await?;
614614
let merged = match existing {
615615
Some(existing) => existing.with_merged(milestone)?,
616616
None => milestone,
@@ -638,7 +638,7 @@ where
638638
for (_, repository) in repositorys {
639639
match repository {
640640
ExistingOrDeleted::Existing(repository) => {
641-
let existing = repository_store.no_optimism_get(&repository.id).await?;
641+
let existing = repository_store.get(&repository.id).await?;
642642
let merged = match existing {
643643
Some(existing) => existing.with_merged(repository)?,
644644
None => repository,

shared/src/sync_engine/initial_sync/ensure_initial_sync_issue_comments.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl<BackendApi: BackendApiTrait, Transport: TransportTrait, GithubApi: GithubAp
4242
.build();
4343
let initial_sync_status = txn
4444
.object_store::<IssueCommentsInitialSyncStatus>()?
45-
.no_optimism_get(&id)
45+
.get(&id)
4646
.await?;
4747
if let Some(initial_sync_status) = initial_sync_status {
4848
match initial_sync_status.status {
@@ -51,7 +51,7 @@ impl<BackendApi: BackendApiTrait, Transport: TransportTrait, GithubApi: GithubAp
5151
page = (txn
5252
.object_store::<IssueComment>()?
5353
.index::<RepositoryIdIndex>()?
54-
.get_all(Some(&id))
54+
.get_all_optimistically(Some(&id))
5555
.await?
5656
.len() as f64
5757
/ f64::from(MAX_PER_PAGE))
@@ -71,7 +71,7 @@ impl<BackendApi: BackendApiTrait, Transport: TransportTrait, GithubApi: GithubAp
7171
.build();
7272
let repo = txn
7373
.object_store::<Repository>()?
74-
.no_optimism_get(&id)
74+
.get(&id)
7575
.await?
7676
.ok_or_else(|| {
7777
SyncErrorSrc::DataModel(format!("repository with id {id:?}: doesn't exist"))
@@ -83,7 +83,7 @@ impl<BackendApi: BackendApiTrait, Transport: TransportTrait, GithubApi: GithubAp
8383
})?;
8484
let repo_owner = txn
8585
.object_store::<User>()?
86-
.no_optimism_get(&repo_owner_id)
86+
.get(&repo_owner_id)
8787
.await?
8888
.ok_or_else(|| {
8989
SyncErrorSrc::DataModel(format!("user with id {repo_owner_id:?}: doesn't exist"))
@@ -118,7 +118,7 @@ impl<BackendApi: BackendApiTrait, Transport: TransportTrait, GithubApi: GithubAp
118118
.unwrap()
119119
.index::<NumberIndex>()
120120
.unwrap()
121-
.get_all(Some(&number))
121+
.get_all_optimistically(Some(&number))
122122
.await
123123
.unwrap()
124124
.into_iter()

shared/src/sync_engine/initial_sync/ensure_initial_sync_issues.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl<BackendApi: BackendApiTrait, Transport: TransportTrait, GithubApi: GithubAp
3535
.build();
3636
let initial_sync_status = txn
3737
.object_store::<IssuesInitialSyncStatus>()?
38-
.no_optimism_get(id)
38+
.get(id)
3939
.await?;
4040
if let Some(initial_sync_status) = initial_sync_status {
4141
match initial_sync_status.status {
@@ -44,7 +44,7 @@ impl<BackendApi: BackendApiTrait, Transport: TransportTrait, GithubApi: GithubAp
4444
page = (txn
4545
.object_store::<Issue>()?
4646
.index::<RepositoryIdIndex>()?
47-
.get_all(Some(id))
47+
.get_all_optimistically(Some(id))
4848
.await?
4949
.len() as f64
5050
/ f64::from(MAX_PER_PAGE))
@@ -64,7 +64,7 @@ impl<BackendApi: BackendApiTrait, Transport: TransportTrait, GithubApi: GithubAp
6464
.build();
6565
let repo = txn
6666
.object_store::<Repository>()?
67-
.no_optimism_get(id)
67+
.get(id)
6868
.await?
6969
.ok_or_else(|| {
7070
SyncErrorSrc::DataModel(format!("repository with id {id:?}: doesn't exist"))
@@ -76,7 +76,7 @@ impl<BackendApi: BackendApiTrait, Transport: TransportTrait, GithubApi: GithubAp
7676
})?;
7777
let repo_owner = txn
7878
.object_store::<User>()?
79-
.no_optimism_get(&repo_owner_id)
79+
.get(&repo_owner_id)
8080
.await?
8181
.ok_or_else(|| {
8282
SyncErrorSrc::DataModel(format!("user with id {repo_owner_id:?}: doesn't exist"))

shared/src/sync_engine/initial_sync/ensure_initial_sync_repository.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl<BackendApi: BackendApiTrait, Transport: TransportTrait, GithubApi: GithubAp
2828
.with_store::<RepositoryInitialSyncStatus>()
2929
.build();
3030
let store = txn.object_store::<RepositoryInitialSyncStatus>()?;
31-
if let Some(RepoSyncStatus::Full) = store.no_optimism_get(id).await?.map(|r| r.status) {
31+
if let Some(RepoSyncStatus::Full) = store.get(id).await?.map(|r| r.status) {
3232
return Ok(());
3333
}
3434
}
@@ -38,7 +38,7 @@ impl<BackendApi: BackendApiTrait, Transport: TransportTrait, GithubApi: GithubAp
3838
.with_store::<Repository>()
3939
.build()
4040
.object_store::<Repository>()?
41-
.no_optimism_get(id)
41+
.get(id)
4242
.await?
4343
.expect("expected repo to be present if an id is passed");
4444

shared/src/sync_engine/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl<BackendApi: BackendApiTrait, Transport: TransportTrait, GithubApi>
9595

9696
let iac = txn
9797
.object_store::<InstallationAccessTokenRow>()?
98-
.no_optimism_get_all()
98+
.get_all()
9999
.await?
100100
.into_iter()
101101
.filter(|iac| {

shared/src/sync_engine/mutations/issues.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl<BackendApi: BackendApiTrait, Transport: TransportTrait, GithubApi: GithubAp
5151

5252
self.db
5353
.object_store_rw::<Issue>()?
54-
.create(optimistic_issue, async move {
54+
.create_optimistically(optimistic_issue, async move {
5555
let conf = this.get_api_conf(&installation_id).await.map_err(|_| ())?;
5656
let id = this.github_api
5757
.issues_slash_create(&conf, &owner_login, &repo_name, issues_create_request)

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@ pub struct IndexWithOptimisticChanges<'txn, IS> {
1818
txn_location: &'static Location<'static>,
1919
}
2020
impl<IS: IndexSpec> IndexWithOptimisticChanges<'_, IS> {
21-
pub async fn get(&self, id: &IS::Type) -> Result<Option<MaybeOptimistic<IS::Store>>, super::Error> {
21+
pub async fn get_optimistically(
22+
&self,
23+
id: &IS::Type,
24+
) -> Result<Option<MaybeOptimistic<IS::Store>>, super::Error> {
2225
self.reactivity_trackers
2326
.borrow_mut()
2427
.add_bulk_read(IS::Store::NAME);
2528

2629
let row = match self
27-
.no_optimism_get(id)
30+
.get(id)
2831
.await
2932
.map_err(|e| super::Error::new(e, self.txn_location))?
3033
{
@@ -48,7 +51,7 @@ impl<IS: IndexSpec> IndexWithOptimisticChanges<'_, IS> {
4851
.or(Some(MaybeOptimistic::new(row, false))))
4952
}
5053

51-
pub(crate) async fn no_optimism_get(
54+
pub(crate) async fn get(
5255
&self,
5356
id: &IS::Type,
5457
) -> Result<Option<IS::Store>, typesafe_idb::Error> {
@@ -59,7 +62,10 @@ impl<IS: IndexSpec> IndexWithOptimisticChanges<'_, IS> {
5962
self.inner.get(id).await
6063
}
6164

62-
pub async fn get_all(&self, value: Option<&IS::Type>) -> Result<Vec<MaybeOptimistic<IS::Store>>, Error> {
65+
pub async fn get_all_optimistically(
66+
&self,
67+
value: Option<&IS::Type>,
68+
) -> Result<Vec<MaybeOptimistic<IS::Store>>, Error> {
6369
self.reactivity_trackers
6470
.borrow_mut()
6571
.add_bulk_read(IS::Store::NAME);
@@ -88,22 +94,26 @@ impl<IS: IndexSpec> IndexWithOptimisticChanges<'_, IS> {
8894
let optimistic_creations = self
8995
.optimistic_changes
9096
.creations
91-
.all_the_latest_downcasted() ;
97+
.all_the_latest_downcasted();
9298
if let Some(value) = value {
9399
all.extend(
94100
optimistic_creations
95101
.into_iter()
96102
.filter(|row| IS::get_index_value(row) == value)
97-
.map(|o| MaybeOptimistic::new(o, true))
103+
.map(|o| MaybeOptimistic::new(o, true)),
98104
);
99105
} else {
100-
all.extend(optimistic_creations.into_iter().map(|o| MaybeOptimistic::new(o, true)));
106+
all.extend(
107+
optimistic_creations
108+
.into_iter()
109+
.map(|o| MaybeOptimistic::new(o, true)),
110+
);
101111
}
102112
Ok(all)
103113
}
104114

105115
#[allow(dead_code)]
106-
pub(crate) async fn no_optimism_get_all(
116+
pub(crate) async fn get_all(
107117
&self,
108118
value: Option<&IS::Type>,
109119
) -> Result<Vec<IS::Store>, typesafe_idb::Error> {

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ where
5151
S: Store + 'static,
5252
Mode: TxnMode<SupportsReadOnly = Present>,
5353
{
54-
pub async fn get(&self, id: &S::Id) -> Result<Option<MaybeOptimistic<S>>, Error> {
54+
pub async fn get_optimistically(&self, id: &S::Id) -> Result<Option<MaybeOptimistic<S>>, Error> {
5555
self.reactivity_trackers
5656
.borrow_mut()
5757
.add_by_id_read(S::NAME, SerializedId::new_from_id::<S>(id));
@@ -75,7 +75,7 @@ where
7575
.map(|o| o.map(|o| MaybeOptimistic::new(o, false)))
7676
}
7777

78-
pub async fn no_optimism_get(&self, id: &S::Id) -> Result<Option<S>, Error> {
78+
pub async fn get(&self, id: &S::Id) -> Result<Option<S>, Error> {
7979
self.reactivity_trackers
8080
.borrow_mut()
8181
.add_by_id_read(S::NAME, SerializedId::new_from_id::<S>(id));
@@ -86,7 +86,7 @@ where
8686
.map_err(|e| super::Error::new(e, self.location))
8787
}
8888

89-
pub async fn get_all(&self) -> Result<Vec<MaybeOptimistic<S>>, super::Error> {
89+
pub async fn get_all_optimistically(&self) -> Result<Vec<MaybeOptimistic<S>>, super::Error> {
9090
self.reactivity_trackers.borrow_mut().add_bulk_read(S::NAME);
9191

9292
let from_db_filtered = self
@@ -121,7 +121,7 @@ where
121121
}
122122

123123
#[allow(dead_code)]
124-
pub(crate) async fn no_optimism_get_all(&self) -> Result<Vec<S>, Error> {
124+
pub(crate) async fn get_all(&self) -> Result<Vec<S>, Error> {
125125
self.reactivity_trackers.borrow_mut().add_bulk_read(S::NAME);
126126

127127
self.inner
@@ -207,7 +207,8 @@ where
207207

208208
Ok(())
209209
}
210-
pub fn update(&self, row: S, update_fut: impl Future<Output = Result<(), ()>> + 'static) {
210+
211+
pub fn update_optimistically(&self, row: S, update_fut: impl Future<Output = Result<(), ()>> + 'static) {
211212
let reactivity_trackers = ReactivityTrackers {
212213
stores_modified: hashmap![S::NAME => hashset![SerializedId::new_from_row(&row)]],
213214
..Default::default()
@@ -223,7 +224,7 @@ where
223224
}
224225
}
225226

226-
pub fn create(&self, row: S, create_fut: impl Future<Output = Result<S::Id, ()>> + 'static) {
227+
pub fn create_optimistically(&self, row: S, create_fut: impl Future<Output = Result<S::Id, ()>> + 'static) {
227228
let reactivity_trackers = ReactivityTrackers {
228229
stores_modified: hashmap![S::NAME => hashset![SerializedId::new_from_row(&row)]],
229230
..Default::default()

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub async fn index_get_no_optimisim_put_overlapping() {
8888
.unwrap()
8989
.index::<RepositoryIdIndex>()
9090
.unwrap()
91-
.get(&4.into())
91+
.get_optimistically(&4.into())
9292
.await;
9393
})
9494
.with_txn_2(async |txn| {
@@ -114,7 +114,7 @@ pub async fn index_get_no_optimisim_put_non_overlapping() {
114114
.unwrap()
115115
.index::<RepositoryIdIndex>()
116116
.unwrap()
117-
.get(&4.into())
117+
.get_optimistically(&4.into())
118118
.await;
119119
})
120120
.with_txn_2(async |txn| {
@@ -139,7 +139,7 @@ pub async fn get_no_optimisim_put_overlapping() {
139139
let _ = txn
140140
.object_store::<Issue>()
141141
.unwrap()
142-
.get(&some_issue_id)
142+
.get_optimistically(&some_issue_id)
143143
.await;
144144
})
145145
.with_txn_2(async |txn| {
@@ -167,7 +167,7 @@ pub async fn get_no_optimisim_put_non_overlapping() {
167167
let _ = txn
168168
.object_store::<Issue>()
169169
.unwrap()
170-
.get(&some_issue_id)
170+
.get_optimistically(&some_issue_id)
171171
.await;
172172
})
173173
.with_txn_2(async |txn| {
@@ -191,7 +191,7 @@ pub async fn get_no_optimisim_put_non_overlapping() {
191191
let _ = txn
192192
.object_store::<Issue>()
193193
.unwrap()
194-
.get(&some_issue_id)
194+
.get_optimistically(&some_issue_id)
195195
.await;
196196
})
197197
.with_txn_2(async |txn| {
@@ -212,7 +212,7 @@ pub async fn get_all_no_optimisim_put_overlapping() {
212212
.make_txn_1(|txn| txn.with_store::<Issue>().build())
213213
.make_txn_2(|txn| txn.with_store::<Issue>().build())
214214
.with_txn_1(async |txn| {
215-
let _ = txn.object_store::<Issue>().unwrap().get_all().await;
215+
let _ = txn.object_store::<Issue>().unwrap().get_all_optimistically().await;
216216
})
217217
.with_txn_2(async |txn| {
218218
txn.object_store::<Issue>()
@@ -235,7 +235,7 @@ pub async fn get_all_no_optimisim_put_non_overlapping() {
235235
let _ = txn
236236
.object_store::<Issue>()
237237
.unwrap()
238-
.get(&Default::default())
238+
.get_optimistically(&Default::default())
239239
.await;
240240
})
241241
.with_txn_2(async |txn| {
@@ -256,12 +256,12 @@ pub async fn get_all_no_optimisim_create_overlapping() {
256256
.make_txn_1(|txn| txn.with_store::<Issue>().build())
257257
.make_txn_2(|txn| txn.with_store::<Issue>().build())
258258
.with_txn_1(async |txn| {
259-
let _ = txn.object_store::<Issue>().unwrap().get_all().await;
259+
let _ = txn.object_store::<Issue>().unwrap().get_all_optimistically().await;
260260
})
261261
.with_txn_2(async |txn| {
262262
txn.object_store::<Issue>()
263263
.unwrap()
264-
.create(Default::default(), async { Ok(Default::default()) });
264+
.create_optimistically(Default::default(), async { Ok(Default::default()) });
265265
})
266266
.should_overlap(true)
267267
.call()
@@ -277,13 +277,13 @@ pub async fn get_all_no_optimisim_create_non_overlapping() {
277277
let _ = txn
278278
.object_store::<Issue>()
279279
.unwrap()
280-
.get(&Default::default())
280+
.get_optimistically(&Default::default())
281281
.await;
282282
})
283283
.with_txn_2(async |txn| {
284284
txn.object_store::<Repository>()
285285
.unwrap()
286-
.create(Default::default(), async { Ok(Default::default()) });
286+
.create_optimistically(Default::default(), async { Ok(Default::default()) });
287287
})
288288
.should_overlap(false)
289289
.call()

0 commit comments

Comments
 (0)