From 3c4bbe3b6b92e059d903eb0d9ca8d49987ad3e94 Mon Sep 17 00:00:00 2001 From: Joscha Date: Sat, 19 Aug 2023 14:39:03 +0200 Subject: [PATCH] Fix new commits not being added to the queue --- ...25ee5fb1a90da7ecaf4bf4b330076f33e74dd.json | 12 ------------ ...9aa9786cb94e2ddda6016fc0e8e0fee46fc98.json | 12 ++++++++++++ src/server/recurring/queue.rs | 19 ++++++++++++++++--- src/server/recurring/repo.rs | 2 +- 4 files changed, 29 insertions(+), 16 deletions(-) delete mode 100644 .sqlx/query-373c31648cfc15a3a42b51dc74025ee5fb1a90da7ecaf4bf4b330076f33e74dd.json create mode 100644 .sqlx/query-3d48dcc84c3d624f7a9f9ebd0399aa9786cb94e2ddda6016fc0e8e0fee46fc98.json diff --git a/.sqlx/query-373c31648cfc15a3a42b51dc74025ee5fb1a90da7ecaf4bf4b330076f33e74dd.json b/.sqlx/query-373c31648cfc15a3a42b51dc74025ee5fb1a90da7ecaf4bf4b330076f33e74dd.json deleted file mode 100644 index a8841f2..0000000 --- a/.sqlx/query-373c31648cfc15a3a42b51dc74025ee5fb1a90da7ecaf4bf4b330076f33e74dd.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "db_name": "SQLite", - "query": "UPDATE commits SET new = false", - "describe": { - "columns": [], - "parameters": { - "Right": 0 - }, - "nullable": [] - }, - "hash": "373c31648cfc15a3a42b51dc74025ee5fb1a90da7ecaf4bf4b330076f33e74dd" -} diff --git a/.sqlx/query-3d48dcc84c3d624f7a9f9ebd0399aa9786cb94e2ddda6016fc0e8e0fee46fc98.json b/.sqlx/query-3d48dcc84c3d624f7a9f9ebd0399aa9786cb94e2ddda6016fc0e8e0fee46fc98.json new file mode 100644 index 0000000..f7ad39e --- /dev/null +++ b/.sqlx/query-3d48dcc84c3d624f7a9f9ebd0399aa9786cb94e2ddda6016fc0e8e0fee46fc98.json @@ -0,0 +1,12 @@ +{ + "db_name": "SQLite", + "query": "UPDATE commits SET new = false WHERE reachable = 2", + "describe": { + "columns": [], + "parameters": { + "Right": 0 + }, + "nullable": [] + }, + "hash": "3d48dcc84c3d624f7a9f9ebd0399aa9786cb94e2ddda6016fc0e8e0fee46fc98" +} diff --git a/src/server/recurring/queue.rs b/src/server/recurring/queue.rs index e3cf525..29aaf96 100644 --- a/src/server/recurring/queue.rs +++ b/src/server/recurring/queue.rs @@ -12,6 +12,7 @@ async fn inner(db: &SqlitePool) -> somehow::Result<()> { let new = sqlx::query!("SELECT hash FROM commits WHERE new AND reachable = 2") .fetch_all(&mut *conn) .await?; + debug!("Found {} new commits", new.len()); // Insert them into the queue for row in new { @@ -29,10 +30,22 @@ async fn inner(db: &SqlitePool) -> somehow::Result<()> { } } - // Mark all commits as old - sqlx::query!("UPDATE commits SET new = false") + // Mark all commits we just added to the queue as old. Commits from + // untracked branches are not marked as old because otherwise we'd miss them + // when they eventually end up in the tracked branches. This can for example + // happen when a tracked branch is fast-forwarded to a commit from an + // untracked branch. + // + // When tracked refs are updated, all new commits are automatically added to + // the queue, since they were still new and have now transitioned to + // reachable = 2. This should hopefully not be too big of a problem since + // usually the main branch is also tracked. I think I'd rather implement + // better queue management tools and graph UI than change this behaviour. + let amount = sqlx::query!("UPDATE commits SET new = false WHERE reachable = 2") .execute(&mut *conn) - .await?; + .await? + .rows_affected(); + debug!("Marked {amount} commits as old"); tx.commit().await?; Ok(()) diff --git a/src/server/recurring/repo.rs b/src/server/recurring/repo.rs index 813f258..60558a4 100644 --- a/src/server/recurring/repo.rs +++ b/src/server/recurring/repo.rs @@ -227,7 +227,7 @@ async fn update_commit_tracked_status(conn: &mut SqliteConnection) -> somehow::R WHEN hash IN reachable THEN 1 \ ELSE 0 \ END \ -" + " ) .execute(conn) .await?;