Don't reindex if there hasn't been any new commits
Diff
src/git.rs | 4 ++--
src/database/indexer.rs | 28 ++++++++++++++++++++++------
src/database/schema/commit.rs | 14 ++++++++++++++
3 files changed, 33 insertions(+), 13 deletions(-)
@@ -530,7 +530,7 @@
_ => (None, false),
};
let line = std::str::from_utf8(diff_line.content()).unwrap();
let line = String::from_utf8_lossy(diff_line.content());
let extension = if should_highlight_as_source {
let path = delta.new_file().path().unwrap();
@@ -547,7 +547,7 @@
let mut html_generator =
ClassedHTMLGenerator::new_with_class_style(syntax, &syntax_set, ClassStyle::Spaced);
html_generator
.parse_html_for_line_which_includes_newline(line)
.parse_html_for_line_which_includes_newline(&line)
.unwrap();
if let Some(class) = class {
write!(diff_output, r#"<span class="diff-{class}">"#).unwrap();
@@ -1,7 +1,7 @@
use git2::Sort;
use std::path::{Path, PathBuf};
use time::OffsetDateTime;
use tracing::info;
use tracing::{info, info_span};
use crate::database::schema::{
commit::Commit,
@@ -44,25 +44,31 @@
let git_repository = git2::Repository::open(scan_path.join(&relative_path)).unwrap();
for reference in git_repository.references().unwrap() {
let reference = if let Some(reference) = reference.as_ref().ok().and_then(|v| v.name())
{
reference
} else {
continue;
};
let reference = reference.unwrap();
if !reference.starts_with("refs/heads/") {
let reference_name = String::from_utf8_lossy(reference.name_bytes());
if !reference_name.starts_with("refs/heads/") {
continue;
}
let span = info_span!("index_update", reference = reference_name.as_ref(), repository = relative_path);
let _entered = span.enter();
info!("Updating indexes for {} on {}", reference, relative_path);
info!("Refreshing indexes");
let commit_tree = db_repository.get().commit_tree(db, reference);
let commit_tree = db_repository.get().commit_tree(db, &reference_name);
if let (Some(latest_indexed), Ok(latest_commit)) = (commit_tree.fetch_latest_one(), reference.peel_to_commit()) {
if latest_commit.id().as_bytes() == &*latest_indexed.get().hash {
info!("No commits since last index");
continue;
}
}
let mut revwalk = git_repository.revwalk().unwrap();
revwalk.set_sorting(Sort::REVERSE).unwrap();
revwalk.push_ref(reference).unwrap();
revwalk.push_ref(&reference_name).unwrap();
let mut i = 0;
for rev in revwalk {
@@ -120,6 +120,20 @@
Self(tree)
}
pub fn fetch_latest_one(&self) -> Option<YokedCommit> {
self.last()
.unwrap()
.map(|(_, value)| {
let value = Box::new(value);
Yoke::try_attach_to_cart(value, |data: &IVec| bincode::deserialize(&data))
.unwrap()
})
}
pub async fn fetch_latest(&self, amount: usize, offset: usize) -> Vec<YokedCommit> {
let latest_key = if let Some((latest_key, _)) = self.last().unwrap() {
let mut latest_key_bytes = [0; std::mem::size_of::<usize>()];