···11use crate::db::types::TrimmedDid;
22-use crate::db::{self, deser_repo_state, ser_repo_state};
22+use crate::db::{self, deser_repo_state, keys, ser_repo_state};
33use crate::state::AppState;
44use crate::types::{RepoStatus, ResyncState};
55use miette::{IntoDiagnostic, Result};
···2828 // move back to pending
2929 let mut batch = state.db.inner.batch();
3030 batch.remove(&state.db.resync, key.clone());
3131- batch.insert(
3232- &state.db.pending,
3333- crate::db::keys::pending_key(&did),
3434- Vec::new(),
3535- );
3131+ batch.insert(&state.db.pending, key.clone(), Vec::new());
36323733 // update repo state back to backfilling
3838- let repo_key = crate::db::keys::repo_key(&did);
3939- if let Some(state_bytes) = state.db.repos.get(&repo_key).into_diagnostic()? {
3434+ if let Some(state_bytes) = state.db.repos.get(&key).into_diagnostic()? {
4035 let mut repo_state = deser_repo_state(&state_bytes)?;
4136 repo_state.status = RepoStatus::Backfilling;
4242- batch.insert(&state.db.repos, &repo_key, ser_repo_state(&repo_state)?);
3737+ batch.insert(&state.db.repos, key, ser_repo_state(&repo_state)?);
4338 }
44394540 state.db.update_count("resync", -1);
···91869287 // move back to pending
9388 state.db.update_count("pending", 1);
9494- if let Err(e) = db
9595- .pending
9696- .insert(crate::db::keys::pending_key(&did), Vec::new())
9797- {
8989+ if let Err(e) = db.pending.insert(keys::repo_key(&did), Vec::new()) {
9890 error!("failed to move {did} to pending: {e}");
9991 db::check_poisoned(&e);
10092 continue;
+6-16
src/backfill/mod.rs
···126126127127 let mut spawned = 0;
128128129129- // limit the number of active tasks based on adaptive limit
130130- // we iterate in reverse to prioritize newer items (LIFO)
131131- // effective key comparison: {timestamp}|{did}
132132- // older timestamps are smaller, newer are larger.
133133- // rev() starts from largest (newest).
134134- for guard in self.state.db.pending.iter().rev() {
129129+ for guard in self.state.db.pending.iter() {
135130 if self.in_flight.len() >= limiter.current_limit {
136131 break;
137132 }
···145140 }
146141 };
147142148148- let did = if key.len() > 9 && key[8] == keys::SEP {
149149- match TrimmedDid::try_from(&key[9..]) {
150150- Ok(d) => d.to_did(),
151151- Err(e) => {
152152- error!("invalid did '{key:?}' in pending: {e}");
153153- continue;
154154- }
143143+ let did = match TrimmedDid::try_from(key.as_ref()) {
144144+ Ok(d) => d.to_did(),
145145+ Err(e) => {
146146+ error!("invalid did '{key:?}' in pending: {e}");
147147+ continue;
155148 }
156156- } else {
157157- error!("invalid did '{key:?}' in pending");
158158- continue;
159149 };
160150161151 if self.in_flight.contains_sync(&did) {