Add limit_commit_ids_to_related setting.

Each template received `commit_ids`, a list of ALL commit hashes known
to Itsy-Gitsy.  For large repos with hundreds of thousands or millions
of commits, this huge list uses lots of memory and takes a long time
to search.

`limit_commit_ids_to_related` reduces the list to just a handful of
relevant commits for certain templates, which can give a massive
performance boost.
This commit is contained in:
Trevor Bentley
2023-01-20 02:26:16 +01:00
parent 5f0f9978c9
commit c257ba12f0
4 changed files with 57 additions and 1 deletions
+30
View File
@@ -454,6 +454,10 @@ impl GitsyGenerator {
})
.map_while(|x| x)
.collect();
if repo_desc.limit_commit_ids_to_related == Some(true) {
let parent_ids: Vec<String> = commits.keys().cloned().collect();
paged_ctx.insert("commit_ids", &parent_ids);
}
paged_ctx.insert("page", &pagination.with_relative_paths());
paged_ctx.insert("history", &page);
paged_ctx.insert("commits", &commits);
@@ -493,6 +497,15 @@ impl GitsyGenerator {
for (_id, commit) in &parsed_repo.commits {
ctx.try_insert("commit", &commit)
.expect("Failed to add commit to template engine.");
if repo_desc.limit_commit_ids_to_related == Some(true) {
let parent_ids: Vec<String> = commit
.parents
.iter()
.filter(|x| parsed_repo.commits.contains_key(*x))
.cloned()
.collect();
ctx.insert("commit_ids", &parent_ids);
}
for (templ_path, out_path) in self.settings.outputs.commit(Some(parsed_repo), Some(commit)) {
let templ_path = templ_path.to_str().expect(&format!(
"ERROR: a summary template path is invalid: {}",
@@ -593,6 +606,14 @@ impl GitsyGenerator {
let mut repo_bytes = 0;
for branch in &parsed_repo.branches {
ctx.insert("branch", branch);
if repo_desc.limit_commit_ids_to_related == Some(true) {
let parent_ids: Vec<String> = [&branch.full_hash]
.iter()
.filter(|x| parsed_repo.commits.contains_key(**x))
.map(|x| (**x).clone())
.collect();
ctx.insert("commit_ids", &parent_ids);
}
for (templ_path, out_path) in self.settings.outputs.branch(Some(parsed_repo), Some(branch)) {
let templ_path = templ_path.to_str().expect(&format!(
"ERROR: a summary template path is invalid: {}",
@@ -693,6 +714,15 @@ impl GitsyGenerator {
let mut repo_bytes = 0;
for tag in &parsed_repo.tags {
ctx.insert("tag", tag);
if repo_desc.limit_commit_ids_to_related == Some(true) {
let parent_ids: Vec<String> = [tag.tagged_id.as_deref()]
.iter()
.map_while(|x| *x)
.filter(|x| parsed_repo.commits.contains_key(*x))
.map(|x| x.to_string())
.collect();
ctx.insert("commit_ids", &parent_ids);
}
if let Some(tagged_id) = tag.tagged_id.as_ref() {
if let Some(commit) = parsed_repo.commits.get(tagged_id) {
ctx.insert("commit", &commit);
+5
View File
@@ -372,6 +372,7 @@ pub struct GitsySettingsRepo {
pub limit_commits: Option<usize>,
pub limit_branches: Option<usize>,
pub limit_tags: Option<usize>,
pub limit_commit_ids_to_related: Option<bool>,
pub limit_tree_depth: Option<usize>,
pub limit_file_size: Option<usize>,
pub limit_repo_size: Option<usize>,
@@ -413,6 +414,7 @@ pub struct GitsySettings {
pub limit_commits: Option<usize>,
pub limit_branches: Option<usize>,
pub limit_tags: Option<usize>,
pub limit_commit_ids_to_related: Option<bool>,
pub limit_tree_depth: Option<usize>,
pub limit_file_size: Option<usize>,
pub limit_repo_size: Option<usize>,
@@ -496,6 +498,7 @@ impl GitsySettings {
global_to_repo!(settings, repo, limit_commits);
global_to_repo!(settings, repo, limit_branches);
global_to_repo!(settings, repo, limit_tags);
global_to_repo!(settings, repo, limit_commit_ids_to_related);
global_to_repo!(settings, repo, limit_tree_depth);
global_to_repo!(settings, repo, limit_file_size);
global_to_repo!(settings, repo, limit_repo_size);
@@ -537,6 +540,7 @@ impl GitsySettings {
limit_commits: settings.limit_commits.clone(),
limit_branches: settings.limit_branches.clone(),
limit_tags: settings.limit_tags.clone(),
limit_commit_ids_to_related: settings.limit_commit_ids_to_related.clone(),
limit_tree_depth: settings.limit_tree_depth.clone(),
limit_file_size: settings.limit_file_size.clone(),
limit_repo_size: settings.limit_repo_size.clone(),
@@ -579,6 +583,7 @@ impl GitsySettings {
limit_commits: settings.limit_commits.clone(),
limit_branches: settings.limit_branches.clone(),
limit_tags: settings.limit_tags.clone(),
limit_commit_ids_to_related: settings.limit_commit_ids_to_related.clone(),
limit_tree_depth: settings.limit_tree_depth.clone(),
limit_file_size: settings.limit_file_size.clone(),
limit_repo_size: settings.limit_repo_size.clone(),