From d0b8ffed5203eef87aaa0e3571d1ade7298173a1 Mon Sep 17 00:00:00 2001 From: Scott Patten Date: Mon, 10 Jul 2023 11:37:44 -0700 Subject: [PATCH] ANE-1050 avoid rescanning unchanged tags and branches (#105) --- CHANGELOG.md | 8 +++++++- Cargo.lock | 2 +- Cargo.toml | 2 +- src/subcommand/run.rs | 15 ++++++++++++++- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91abb5f7..10d1f1bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,13 @@ +## v0.2.3 + +Bug fix: + +- Broker was not properly noting which revisions it had scanned, so it was scanning all recent tags and branches on every poll cycle. This is now fixed. + ## v0.2.2 -Bug fix: +Bug fix: - Broker now copies its debug bundle (generated during `broker fix`) from the system temp location instead of renaming. This resolves issues preventing debug bundles from being stored for Linux installations where the temporary location diff --git a/Cargo.lock b/Cargo.lock index 876334ab..81816087 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -211,7 +211,7 @@ dependencies = [ [[package]] name = "broker" -version = "0.2.3-pre" +version = "0.2.3" dependencies = [ "aho-corasick 0.7.20", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index 883ac394..1b8d5190 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "broker" -version = "0.2.3-pre" +version = "0.2.3" edition = "2021" description = "The bridge between FOSSA and internal DevOps services" readme = "README.md" diff --git a/src/subcommand/run.rs b/src/subcommand/run.rs index 97c1754f..74e23007 100644 --- a/src/subcommand/run.rs +++ b/src/subcommand/run.rs @@ -65,6 +65,10 @@ pub enum Error { #[error("handle task")] TaskHandle, + /// If we fail to set a task's state in the sqlite DB, this error is raised. + #[error("set task state")] + TaskSetState, + /// If we fail to mark a task complete, this error is raised. #[error("mark task complete")] TaskComplete, @@ -241,7 +245,7 @@ async fn poll_integration( // No previous state; this must be a new reference. Ok(None) => Some(Ok(reference)), // There was previous state, it's only new if the state is different. - // We're assuming "different state" always means "newer state". + // We're assuming "different state" always means "newer state". // This is because state is currently expressed as a git commit string, // which on its own doesn't have any form of ordering. Ok(Some(db_state)) => { @@ -318,6 +322,7 @@ async fn scan_git_references( .await .change_context(Error::DownloadFossaCli) .describe("Broker relies on fossa-cli to perform analysis of your projects")?; + let db = &ctx.db; loop { let guard = receiver.recv().await.change_context(Error::TaskReceive)?; @@ -331,6 +336,14 @@ async fn scan_git_references( .send(&upload) .await .change_context(Error::TaskEnqueue)?; + let remote = job.integration.remote().to_owned(); + let coordinate = job.reference.as_coordinate(&remote); + let state = job.reference.as_state(); + + // Mark this reference as scanned in the local DB + db.set_state(&coordinate, state) + .await + .change_context(Error::TaskSetState)?; guard.commit().change_context(Error::TaskComplete)?; }