Skip to content

Commit

Permalink
Add commit stats cache / Make display of commit stats (red/green bars…
Browse files Browse the repository at this point in the history
… in the main view) configurable with . Can greatly improve performance if your commits regularly contain changes to very large files.
  • Loading branch information
phil294 committed Nov 18, 2024
1 parent adc3986 commit c3ca376
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ Please consider opening an issue or PR if you think a certain action or option w
"maximum": 1,
"default": 0.4
},
"git-log--graph.disable-commit-stats": {
"description": "If active, the stats for commits in the main view (green/red bars showing the amounts of changes, e.g. \"25 in 4\") will not be shown anymore. This can greatly improve performance if your commits regularly contain changes to very large files.",
"type": "boolean",
"default": false
},
"git-log--graph.custom-css": {
"description": "An abitrary string of CSS that will be injected into the main web view. Example: * { text-transform: uppercase; }",
"type": "string",
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@
"minimum": 1,
"default": 20
},
"git-log--graph.disable-commit-stats": {
"description": "If active, the stats for commits in the main view (green/red bars showing the amounts of changes, e.g. \"25 in 4\") will not be shown anymore. This can greatly improve performance if your commits regularly contain changes to very large files.",
"type": "boolean",
"default": false
},
"git-log--graph.custom-css": {
"description": "An abitrary string of CSS that will be injected into the main web view",
"type": "string",
Expand Down
7 changes: 7 additions & 0 deletions web/src/state/commit-stats.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { git } from '../bridge'

/** @type {Record<string, Commit["stats"]>} */
let stats_cache = {}

let is_updating_commit_stats = false
/** @type {Commit[]} */
let queued_commits_for_update_stats = []
export let update_commit_stats = async (/** @type {Commit[]} */ commits_, level = 0) => {
for (let commit of commits_)
commit.stats = stats_cache[commit.hash]
commits_ = commits_.filter(c => ! c.stats)
if (! commits_.length || level === 0 && /* probably heavily overloaded */queued_commits_for_update_stats.length > 120)
return
commits_.forEach(commit => commit.stats = {}) // Prevent from running them twice
Expand Down Expand Up @@ -84,6 +90,7 @@ async function update_commit_stats_full(/** @type {Commit[]} */ commits_) {
console.warn('Commit stats files_changed mismatch between fast and full mode. Fast: ', commit.stats?.files_changed, ', full:', stat.files_changed, ', commit: ', commit)

commit.stats = stat
stats_cache[hash] = stat
}
// console.timeEnd('update_commit_stats_full')
}
3 changes: 2 additions & 1 deletion web/src/views/MainView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@ watch(visible_commits, async () => {
commit.hash && ! commit.stats)
if (! visible_cp.length)
return
await store.update_commit_stats(visible_cp)
if (! store.config.value['disable-commit-stats'])
await store.update_commit_stats(visible_cp)
})
let visible_branches = computed(() => [
...new Set(visible_commits.value.flatMap((commit) =>
Expand Down

0 comments on commit c3ca376

Please sign in to comment.