Skip to content

Commit dc70d90

Browse files
committed
handle large directories a bit better
Signed-off-by: Andrew Thornton <[email protected]>
1 parent f89f634 commit dc70d90

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

routers/web/repo/view.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,22 @@ func LastCommit(ctx *context.Context) {
647647
return
648648
}
649649

650+
var treeNames []string
651+
paths := make([]string, 0, 5)
652+
if len(ctx.Repo.TreePath) > 0 {
653+
treeNames = strings.Split(ctx.Repo.TreePath, "/")
654+
for i := range treeNames {
655+
paths = append(paths, strings.Join(treeNames[:i+1], "/"))
656+
}
657+
658+
ctx.Data["HasParentPath"] = true
659+
if len(paths)-2 >= 0 {
660+
ctx.Data["ParentPath"] = "/" + paths[len(paths)-2]
661+
}
662+
}
663+
branchLink := ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL()
664+
ctx.Data["BranchLink"] = branchLink
665+
650666
ctx.HTML(http.StatusOK, tplRepoViewList)
651667
}
652668

templates/repo/view_list.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
{{$entry := $item.Entry}}
4848
{{$commit := $item.Commit}}
4949
{{$subModuleFile := $item.SubModuleFile}}
50-
<tr data-entryname="{{$entry.Name}}" data-ready="{{if $commit}}true{{else}}false{{end}}" {{if not $commit}}class="notready"{{end}}>
50+
<tr data-entryname="{{$entry.Name}}" data-ready="{{if $commit}}true{{else}}false{{end}}" class="{{if not $commit}}not{{end}}ready entry">
5151
<td class="name four wide">
5252
<span class="truncate">
5353
{{if $entry.IsSubModule}}

web_src/js/features/lastcommitloader.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ export async function initLastCommitLoader() {
55

66
const entries = $('table#repo-files-table tr.notready')
77
.map((_, v) => {
8-
entryMap[$(v).data('entryname')] = $(v);
9-
return $(v).data('entryname');
8+
entryMap[$(v).attr('data-entryname')] = $(v);
9+
return $(v).attr('data-entryname');
1010
})
1111
.get();
1212

@@ -16,6 +16,15 @@ export async function initLastCommitLoader() {
1616

1717
const lastCommitLoaderURL = $('table#repo-files-table').data('lastCommitLoaderUrl');
1818

19+
if (entries.length > 200) {
20+
$.post(lastCommitLoaderURL, {
21+
_csrf: csrf,
22+
}, (data) => {
23+
$('table#repo-files-table').replaceWith(data);
24+
});
25+
return;
26+
}
27+
1928
$.post(lastCommitLoaderURL, {
2029
_csrf: csrf,
2130
'f': entries,
@@ -25,7 +34,7 @@ export async function initLastCommitLoader() {
2534
$('table#repo-files-table .commit-list').replaceWith(row);
2635
return;
2736
}
28-
entryMap[$(row).data('entryname')].replaceWith(row);
37+
entryMap[$(row).attr('data-entryname')].replaceWith(row);
2938
});
3039
});
3140
}

0 commit comments

Comments
 (0)