From eb04ecb9cdc0f3c7b91a2979b252659543ac65df Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Sun, 17 Jul 2022 21:21:05 +0100 Subject: [PATCH] Collect revs before opening transaction so sled doesn't lock the db for a long time --- src/database/indexer.rs | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/src/database/indexer.rs b/src/database/indexer.rs index 926ee69..4c76ed9 100644 --- a/src/database/indexer.rs +++ a/src/database/indexer.rs @@ -64,30 +64,25 @@ let commit_tree = db_repository.commit_tree(db, reference); + // TODO: only scan revs from the last time we looked + let mut revwalk = git_repository.revwalk().unwrap(); + revwalk.set_sorting(Sort::REVERSE).unwrap(); + revwalk.push_ref(reference).unwrap(); + let revs: Vec<_> = revwalk.collect::>().unwrap(); + + let git_repository = &git_repository; + commit_tree - .transaction::<_, _, std::io::Error>(|tx| { - // TODO: only scan revs from the last time we looked - let mut revwalk = git_repository.revwalk().unwrap(); - revwalk.set_sorting(Sort::REVERSE).unwrap(); - revwalk.push_ref(reference).unwrap(); - - let mut i = 0; - for rev in revwalk { - let rev = rev.unwrap(); - let commit = if let Ok(commit) = git_repository.find_commit(rev) { - commit - } else { - continue; - }; - - i += 1; + .transaction::<_, _, std::io::Error>(move |tx| { + for (i, rev) in revs.iter().enumerate() { + let commit = git_repository.find_commit(*rev).unwrap(); Commit::from(commit).insert(tx, i); } // a complete and utter hack to remove potentially dropped commits from our tree, // we'll need to add `clear()` to sled's tx api to remove this - for to_remove in (i + 1)..(i + 100) { + for to_remove in (revs.len() + 1)..(revs.len() + 100) { tx.remove(&to_remove.to_be_bytes())?; } -- rgit 0.1.3