Improve performance by reordering inserts

This commit is contained in:
Joscha 2023-08-05 00:12:14 +02:00
parent 6651c72ea3
commit 087416bf38

View file

@ -49,12 +49,16 @@ async fn add_new_commits_to_db(db: &SqlitePool, repo: &Repository) -> anyhow::Re
.collect::<Result<Vec<_>, _>>()?; .collect::<Result<Vec<_>, _>>()?;
debug!("Found {} new commits in repo", new_commits.len()); 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(); let hash = commit.id.to_string();
sqlx::query!("INSERT OR IGNORE INTO commits (hash) VALUES (?)", hash) sqlx::query!("INSERT OR IGNORE INTO commits (hash) VALUES (?)", hash)
.execute(&mut *conn) .execute(&mut *conn)
.await?; .await?;
}
debug!("Inserted commits");
for commit in &new_commits {
let hash = commit.id.to_string();
for parent in commit.parent_ids() { for parent in commit.parent_ids() {
let parent_hash = parent.to_string(); let parent_hash = parent.to_string();
sqlx::query!( sqlx::query!(
@ -66,6 +70,7 @@ async fn add_new_commits_to_db(db: &SqlitePool, repo: &Repository) -> anyhow::Re
.await?; .await?;
} }
} }
debug!("Inserted commit links");
debug!("Finished adding new commits to the db"); debug!("Finished adding new commits to the db");
tx.commit().await?; tx.commit().await?;