Collect revs before opening transaction so sled doesn't lock the db for a long time
Diff
src/database/indexer.rs | 29 ++++++++++++-----------------
1 file changed, 12 insertions(+), 17 deletions(-)
@@ -64,30 +64,25 @@
let commit_tree = db_repository.commit_tree(db, reference);
let mut revwalk = git_repository.revwalk().unwrap();
revwalk.set_sorting(Sort::REVERSE).unwrap();
revwalk.push_ref(reference).unwrap();
let revs: Vec<_> = revwalk.collect::<Result<_, _>>().unwrap();
let git_repository = &git_repository;
commit_tree
.transaction::<_, _, std::io::Error>(|tx| {
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);
}
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())?;
}