🏡 index : ~doyle/rgit.git

author Jordan Doyle <jordan@doyle.la> 2022-07-17 21:21:05.0 +01:00:00
committer Jordan Doyle <jordan@doyle.la> 2022-07-17 21:21:05.0 +01:00:00
commit
eb04ecb9cdc0f3c7b91a2979b252659543ac65df [patch]
tree
431dc4e5a2b1935d2ecc3f5ebfaf948bbefaa626
parent
dada791df64c6fe5ef6e447da817d8e0fb2db255
download
eb04ecb9cdc0f3c7b91a2979b252659543ac65df.tar.gz

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(-)

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::<Result<_, _>>().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())?;
                    }