···277277 conn: &mut AsyncPgConnection,
278278 commit: AtpCommitEvent,
279279) -> eyre::Result<()> {
280280+ let (current_rev, sync_status) = db::get_repo_info(conn, &commit.repo).await?.unzip();
281281+280282 // what's the backfill status of this account? this respects locks held by the backfiller.
281283 // we should drop events for 'dirty' and queue 'processing'
282284 // if we can't find the actor, we should add them and then drop the event as with 'dirty'
283283- let is_active = match db::account_sync_status(conn, &commit.repo).await? {
285285+ let is_active = match sync_status {
284286 Some(ActorSyncState::Synced) => true,
285287 Some(ActorSyncState::Processing) => false,
286288 Some(ActorSyncState::Dirty) => {
···325327 }
326328 };
327329330330+ if let Some(current_rev) = current_rev.flatten() {
331331+ if current_rev >= commit.rev {
332332+ tracing::debug!("Got a repo update older than the current rev. not processing ops.");
333333+ return Ok(());
334334+ }
335335+ }
336336+328337 // turn the car slice into a map of cid:block
329338 let car_reader = iroh_car::CarReader::new(commit.blocks.as_slice()).await?;
330339 let blocks = car_reader
···333342 .collect::<HashMap<Cid, Vec<u8>>>()
334343 .await;
335344336336- conn.transaction::<_, diesel::result::Error, _>(|t| {
337337- Box::pin(async move {
338338- if is_active {
339339- // ensure new repo rev > current rev, but only when the repo is synced
340340- // (if repo is processing, they'll end up on the queue anyway)
341341- let updated =
342342- db::update_repo_version(t, &commit.repo, &commit.rev, commit.commit).await?;
343343-344344- if !updated {
345345- tracing::debug!(
346346- "Got a repo update older than the current rev. not processing ops."
347347- );
348348- return Ok(false);
349349- }
345345+ if is_active {
346346+ conn.transaction::<_, diesel::result::Error, _>(|t| {
347347+ Box::pin(async move {
348348+ db::update_repo_version(t, &commit.repo, &commit.rev, commit.commit).await?;
350349351350 for op in &commit.ops {
352351 process_op(t, &mut state.idxc_tx, &commit.repo, op, &blocks).await?;
353352 }
354354- } else {
355355- let items = commit
356356- .ops
357357- .iter()
358358- .filter_map(|op| process_op_bf(&commit.repo, op, &blocks))
359359- .collect::<Vec<_>>();
360360-361361- let items = serde_json::to_value(items).unwrap_or_default();
362362-363363- db::write_backfill_row(t, &commit.repo, &commit.rev, commit.commit, items).await?;
364364- }
365365-366366- Ok(true)
353353+ Ok(true)
354354+ })
367355 })
368368- })
369369- .await?;
356356+ .await?;
357357+ } else {
358358+ let items = commit
359359+ .ops
360360+ .iter()
361361+ .filter_map(|op| process_op_bf(&commit.repo, op, &blocks))
362362+ .collect::<Vec<_>>();
363363+ let items = serde_json::to_value(items).unwrap_or_default();
364364+365365+ db::write_backfill_row(conn, &commit.repo, &commit.rev, commit.commit, items).await?;
366366+ }
370367371368 Ok(())
372369}