Skip to content

Commit b1701f2

Browse files
committed
store: Asyncify remaining methods in copy
1 parent 68cbcd8 commit b1701f2

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

store/postgres/src/copy.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ impl CopyState {
297297
}
298298
}
299299

300-
pub(crate) fn source(
300+
pub(crate) async fn source(
301301
conn: &mut PgConnection,
302302
dst: &Site,
303303
) -> Result<Option<DeploymentId>, StoreError> {
@@ -429,7 +429,7 @@ impl TableState {
429429
Ok(states)
430430
}
431431

432-
fn record_progress(
432+
async fn record_progress(
433433
&mut self,
434434
conn: &mut PgConnection,
435435
elapsed: Duration,
@@ -466,7 +466,7 @@ impl TableState {
466466
Ok(())
467467
}
468468

469-
fn record_finished(&self, conn: &mut PgConnection) -> Result<(), StoreError> {
469+
async fn record_finished(&self, conn: &mut PgConnection) -> Result<(), StoreError> {
470470
use copy_table_state as cts;
471471

472472
update(
@@ -509,16 +509,20 @@ impl TableState {
509509

510510
deployment::update_entity_count(conn, &self.dst_site, count).await?;
511511

512-
self.record_progress(conn, duration)?;
512+
self.record_progress(conn, duration).await?;
513513

514514
if self.finished() {
515-
self.record_finished(conn)?;
515+
self.record_finished(conn).await?;
516516
}
517517

518518
Ok(Status::Finished)
519519
}
520520

521-
fn set_batch_size(&mut self, conn: &mut PgConnection, size: usize) -> Result<(), StoreError> {
521+
async fn set_batch_size(
522+
&mut self,
523+
conn: &mut PgConnection,
524+
size: usize,
525+
) -> Result<(), StoreError> {
522526
use copy_table_state as cts;
523527

524528
self.batcher.set_batch_size(size);
@@ -835,10 +839,8 @@ impl CopyTableWorker {
835839
// that is hard to predict. This mechanism ensures
836840
// that if our estimation is wrong, the consequences
837841
// aren't too severe.
838-
conn.transaction_async(|conn| {
839-
async { self.table.set_batch_size(conn, 1) }.scope_boxed()
840-
})
841-
.await?;
842+
conn.transaction_async(|conn| self.table.set_batch_size(conn, 1).scope_boxed())
843+
.await?;
842844
}
843845
};
844846

store/postgres/src/deployment_store.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,9 +595,12 @@ impl DeploymentStore {
595595

596596
/// Return the source if `site` or `None` if `site` is neither a graft
597597
/// nor a copy
598-
pub(crate) fn source_of_copy(&self, site: &Site) -> Result<Option<DeploymentId>, StoreError> {
598+
pub(crate) async fn source_of_copy(
599+
&self,
600+
site: &Site,
601+
) -> Result<Option<DeploymentId>, StoreError> {
599602
let mut conn = self.get_conn()?;
600-
crate::copy::source(&mut conn, site)
603+
crate::copy::source(&mut conn, site).await
601604
}
602605

603606
// Only used for tests

store/postgres/src/writable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ impl SyncStore {
464464
// Handle on_sync actions. They only apply to copies (not
465465
// grafts) so we make sure that the source, if it exists, has
466466
// the same hash as `self.site`
467-
if let Some(src) = self.writable.source_of_copy(&self.site)? {
467+
if let Some(src) = self.writable.source_of_copy(&self.site).await? {
468468
if let Some(src) = self.maybe_find_site(src).await? {
469469
if src.deployment == self.site.deployment {
470470
let on_sync = self.writable.on_sync(&self.site).await?;

0 commit comments

Comments
 (0)