From 087416bf3825abf79dd58759bf6e70ce6c49501e Mon Sep 17 00:00:00 2001 From: Joscha Date: Sat, 5 Aug 2023 00:12:14 +0200 Subject: [PATCH] Improve performance by reordering inserts --- src/update.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/update.rs b/src/update.rs index 08616a7..ab11ff9 100644 --- a/src/update.rs +++ b/src/update.rs @@ -49,12 +49,16 @@ async fn add_new_commits_to_db(db: &SqlitePool, repo: &Repository) -> anyhow::Re .collect::, _>>()?; debug!("Found {} new commits in repo", new_commits.len()); - for commit in new_commits { + for commit in &new_commits { let hash = commit.id.to_string(); sqlx::query!("INSERT OR IGNORE INTO commits (hash) VALUES (?)", hash) .execute(&mut *conn) .await?; + } + debug!("Inserted commits"); + for commit in &new_commits { + let hash = commit.id.to_string(); for parent in commit.parent_ids() { let parent_hash = parent.to_string(); sqlx::query!( @@ -66,6 +70,7 @@ async fn add_new_commits_to_db(db: &SqlitePool, repo: &Repository) -> anyhow::Re .await?; } } + debug!("Inserted commit links"); debug!("Finished adding new commits to the db"); tx.commit().await?;