Skip to content

Commit

Permalink
Fix duplicate commit stats loading
Browse files Browse the repository at this point in the history
Was heavy on performance
  • Loading branch information
phil294 committed Oct 20, 2024
1 parent 894d3b1 commit 13e12a9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
20 changes: 19 additions & 1 deletion web/src/state/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,24 @@ export let refresh_main_view = ({ before_execute } = {}) => {
return main_view_git_input_ref.value?.value?.execute({ before_execute })
}

let is_updating_commit_stats = false
/** @type {Commit[]} */
let queued_commits_for_update_stats = []
export let update_commit_stats = async (/** @type {Commit[]} */ commits_) => {
if (is_updating_commit_stats)
return queued_commits_for_update_stats.push(...commits_)
is_updating_commit_stats = true
await work_update_commit_stats(commits_)
is_updating_commit_stats = false
if (queued_commits_for_update_stats.length) {
update_commit_stats(queued_commits_for_update_stats.filter(c => ! c.stats))
queued_commits_for_update_stats = []
}
}
/** Can be *very* slow in very big repos so it's important to keep it to a minimum */
async function work_update_commit_stats(/** @type {Commit[]} */ commits_) {
if (! commits_.length)
return
let data = await git('show --format="%h" --shortstat ' + commits_.map((c) => c.hash).join(' '))
if (! data)
return
Expand Down Expand Up @@ -274,7 +291,8 @@ export let init = () => {
git_log('log --graph --author-date-order --date=iso-local --pretty={EXT_FORMAT} -n 100 --all --color=never',
{ fetch_stash_refs: false, fetch_branches: false }).then((parsed) =>
commits.value = parsed.commits
.concat({ subject: '..........Loading more..........', author_email: '', hash: '-', index_in_graph_output: -1, vis_lines: [{ y0: 0.5, yn: 0.5, x0: 0, xn: 2000, branch: { color: 'yellow', type: 'branch', name: '', id: '' } }], author_name: '', hash_long: '', refs: [] }))
.concat({ subject: '..........Loading more..........', author_email: '', hash: '-', index_in_graph_output: -1, vis_lines: [{ y0: 0.5, yn: 0.5, x0: 0, xn: 2000, branch: { color: 'yellow', type: 'branch', name: '', id: '' } }], author_name: '', hash_long: '', refs: [] })
.map(c => ({ ...c, stats: /* to prevent loading them */ { files_changed: 0, insertions: 0, deletions: 0 } })))

add_push_listener('config-change', async () => {
await refresh_config()
Expand Down
1 change: 1 addition & 0 deletions web/src/views/CommitFileChanges.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ import { stateful_computed, refresh_main_view } from '../state/store.js'
import { createReusableTemplate } from '@vueuse/core'
import file_extension_icon_path_mapping from '../state/file-extension-icon-path-mapping.json'
// TODO: share/extend type and component with commit.stats?
/**
* @typedef {{
* path: string
Expand Down
18 changes: 10 additions & 8 deletions web/src/views/CommitRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@
{{ commit.author_name }}
</div>
<div class="stats flex-noshrink row align-center justify-flex-end gap-5">
<div v-if="commit.stats" class="changes" title="Changed lines in amount of files">
<span>
<strong>{{ commit.stats.insertions + commit.stats.deletions }}</strong>
</span>
<span class="grey"> in</span>
<span class="grey">{{ commit.stats.files_changed }}</span>
</div>
<progress v-if="commit.stats" :value="(commit.stats.insertions / (commit.stats.insertions + commit.stats.deletions)) || 0" class="diff" title="Ratio insertions / deletions" />
<template v-if="commit.stats?.files_changed">
<div class="changes" title="Changed lines in amount of files">
<span>
<strong>{{ commit.stats.insertions + commit.stats.deletions }}</strong>
</span>
<span class="grey"> in </span>
<span class="grey">{{ commit.stats.files_changed }}</span>
</div>
<progress :value="(commit.stats.insertions / (commit.stats.insertions + commit.stats.deletions)) || 0" class="diff" title="Ratio insertions / deletions" />
</template>
</div>
<div class="datetime flex-noshrink align-center">
{{ commit.datetime }}
Expand Down
2 changes: 1 addition & 1 deletion web/src/views/MainView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ let scroll_item_height = computed(() =>
store.config.value['row-height'])
watch(visible_commits, async () => {
let visible_cp = [...visible_commits.value].filter((commit) => // to avoid race conditions
let visible_cp = visible_commits.value.filter((commit) =>
commit.hash && ! commit.stats)
if (! visible_cp.length)
return
Expand Down

0 comments on commit 13e12a9

Please sign in to comment.