@@ -268,9 +268,25 @@ impl BuildQueue {
268268 pub fn get_new_crates ( & self , index : & Index ) -> Result < usize > {
269269 let mut conn = self . db . get ( ) ?;
270270 let diff = index. diff ( ) ?;
271- let ( mut changes, oid) = diff. peek_changes_ordered ( ) ?;
271+
272+ let Some ( last_seen_reference) = self . last_seen_reference ( ) ? else {
273+ // we should always have a last seen reference in the database, other than when
274+ // initialising a new deployment (e.g. dev/test/staging), in those cases we don't want
275+ // to rebuild the entire world, so we get crates-index-diff to fetch the current state
276+ // then use the current head as the base and will only start building new crates from
277+ // now on
278+ let ( _, oid) = diff. peek_changes_ordered ( ) ?;
279+ warn ! ( "no last_seen_reference in database, setting to current head {oid}" ) ;
280+ self . set_last_seen_reference ( oid) ?;
281+ return Ok ( 0 ) ;
282+ } ;
283+ diff. set_last_seen_reference ( last_seen_reference) ?;
284+
285+ let ( mut changes, new_reference) = diff. peek_changes_ordered ( ) ?;
272286 let mut crates_added = 0 ;
273287
288+ debug ! ( "queueing changes from {last_seen_reference} to {new_reference}" ) ;
289+
274290 // I believe this will fix ordering of queue if we get more than one crate from changes
275291 changes. reverse ( ) ;
276292
@@ -341,14 +357,10 @@ impl BuildQueue {
341357 }
342358 }
343359
344- // additionally set the reference in the database
360+ // set the reference in the database
345361 // so this survives recreating the registry watcher
346362 // server.
347- self . set_last_seen_reference ( oid) ?;
348-
349- // store the last seen reference as git reference in
350- // the local crates.io index repo.
351- diff. set_last_seen_reference ( oid) ?;
363+ self . set_last_seen_reference ( new_reference) ?;
352364
353365 Ok ( crates_added)
354366 }
0 commit comments