diff --git a/.sqlx/query-6398e5b1dce1142d3460f9d067588bcb42b0be5278ce7524280a4786c8b41786.json b/.sqlx/query-6398e5b1dce1142d3460f9d067588bcb42b0be5278ce7524280a4786c8b41786.json new file mode 100644 index 0000000..b59c1be --- /dev/null +++ b/.sqlx/query-6398e5b1dce1142d3460f9d067588bcb42b0be5278ce7524280a4786c8b41786.json @@ -0,0 +1,12 @@ +{ + "db_name": "SQLite", + "query": "\nWITH RECURSIVE reachable(hash) AS (\n SELECT hash FROM tracked_refs\n UNION\n SELECT parent FROM commit_links\n JOIN reachable ON hash = child\n)\n\nUPDATE commits\nSET tracked = (hash IN reachable)\n", + "describe": { + "columns": [], + "parameters": { + "Right": 0 + }, + "nullable": [] + }, + "hash": "6398e5b1dce1142d3460f9d067588bcb42b0be5278ce7524280a4786c8b41786" +} diff --git a/migrations/1_commits.sql b/migrations/1_commits.sql index 4d735c7..67aed59 100644 --- a/migrations/1_commits.sql +++ b/migrations/1_commits.sql @@ -1,6 +1,7 @@ CREATE TABLE commits ( - hash TEXT NOT NULL PRIMARY KEY, - new INT NOT NULL DEFAULT 1 + hash TEXT NOT NULL PRIMARY KEY, + new INT NOT NULL DEFAULT 1, + tracked INT NOT NULL DEFAULT 0 ) STRICT; CREATE TABLE commit_links ( diff --git a/src/recurring/repo.rs b/src/recurring/repo.rs index 5e29d3d..79bb549 100644 --- a/src/recurring/repo.rs +++ b/src/recurring/repo.rs @@ -127,6 +127,25 @@ async fn update_tracked_refs(conn: &mut SqliteConnection, repo: &Repository) -> Ok(()) } +async fn update_commit_tracked_status(conn: &mut SqliteConnection) -> anyhow::Result<()> { + sqlx::query!( + " +WITH RECURSIVE reachable(hash) AS ( + SELECT hash FROM tracked_refs + UNION + SELECT parent FROM commit_links + JOIN reachable ON hash = child +) + +UPDATE commits +SET tracked = (hash IN reachable) +" + ) + .execute(conn) + .await?; + Ok(()) +} + pub async fn update(db: &SqlitePool, repo: &Repository) -> anyhow::Result<()> { debug!("Updating repo"); let mut tx = db.begin().await?; @@ -136,7 +155,6 @@ pub async fn update(db: &SqlitePool, repo: &Repository) -> anyhow::Result<()> { debug!("Loaded {} commits from the db", old.len()); let repo_is_new = old.is_empty(); - if repo_is_new { info!("Initializing new repo"); } @@ -164,6 +182,8 @@ pub async fn update(db: &SqlitePool, repo: &Repository) -> anyhow::Result<()> { } update_tracked_refs(conn, repo).await?; + update_commit_tracked_status(conn).await?; + debug!("Updated tracked refs"); tx.commit().await?; if repo_is_new {