Skip to content

Commit fa1862c

Browse files
Nemo157jyn514
authored andcommitted
Always use the last_seen_reference from the database
1 parent 16580c5 commit fa1862c

File tree

2 files changed

+20
-24
lines changed

2 files changed

+20
-24
lines changed

src/build_queue.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/utils/daemon.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use anyhow::{anyhow, Context as _, Error};
1212
use std::sync::Arc;
1313
use std::thread;
1414
use std::time::{Duration, Instant};
15-
use tracing::{debug, error, info};
15+
use tracing::{debug, info};
1616

1717
/// Run the registry watcher
1818
/// NOTE: this should only be run once, otherwise crates would be added
@@ -24,22 +24,6 @@ pub fn watch_registry(
2424
) -> Result<(), Error> {
2525
let mut last_gc = Instant::now();
2626

27-
// On startup we fetch the last seen index reference from
28-
// the database and set it in the local index repository.
29-
match build_queue.last_seen_reference() {
30-
Ok(Some(oid)) => {
31-
index.diff()?.set_last_seen_reference(oid)?;
32-
}
33-
Ok(None) => {}
34-
Err(err) => {
35-
error!(
36-
"queue locked because of invalid last_seen_index_reference in database: {:?}",
37-
err
38-
);
39-
build_queue.lock()?;
40-
}
41-
}
42-
4327
loop {
4428
if build_queue.is_locked()? {
4529
debug!("Queue is locked, skipping checking new crates");

0 commit comments

Comments
 (0)