aboutsummaryrefslogtreecommitdiffstats
path: root/web_src
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-10-08 14:08:22 +0100
committerGitHub <noreply@github.com>2021-10-08 15:08:22 +0200
commit001dbf100de40f19c7ade5b8f013fbcccbe09ec3 (patch)
tree0b1a57f8efbb2e941fe4c344005a70ec76ad57d1 /web_src
parent88fa9f3fb168bc6c9c2bdc6341b83bc048b38846 (diff)
downloadgitea-001dbf100de40f19c7ade5b8f013fbcccbe09ec3.tar.gz
gitea-001dbf100de40f19c7ade5b8f013fbcccbe09ec3.zip
Defer Last Commit Info (#16467)
One of the biggest reasons for slow repository browsing is that we wait until last commit information has been generated for all files in the repository. This PR proposes deferring this generation to a new POST endpoint that does the look up outside of the main page request. Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'web_src')
-rw-r--r--web_src/js/features/lastcommitloader.js40
-rw-r--r--web_src/js/index.js2
2 files changed, 42 insertions, 0 deletions
diff --git a/web_src/js/features/lastcommitloader.js b/web_src/js/features/lastcommitloader.js
new file mode 100644
index 0000000000..964255f229
--- /dev/null
+++ b/web_src/js/features/lastcommitloader.js
@@ -0,0 +1,40 @@
+const {csrf} = window.config;
+
+export async function initLastCommitLoader() {
+ const entryMap = {};
+
+ const entries = $('table#repo-files-table tr.notready')
+ .map((_, v) => {
+ entryMap[$(v).attr('data-entryname')] = $(v);
+ return $(v).attr('data-entryname');
+ })
+ .get();
+
+ if (entries.length === 0) {
+ return;
+ }
+
+ const lastCommitLoaderURL = $('table#repo-files-table').data('lastCommitLoaderUrl');
+
+ if (entries.length > 200) {
+ $.post(lastCommitLoaderURL, {
+ _csrf: csrf,
+ }, (data) => {
+ $('table#repo-files-table').replaceWith(data);
+ });
+ return;
+ }
+
+ $.post(lastCommitLoaderURL, {
+ _csrf: csrf,
+ 'f': entries,
+ }, (data) => {
+ $(data).find('tr').each((_, row) => {
+ if (row.className === 'commit-list') {
+ $('table#repo-files-table .commit-list').replaceWith(row);
+ return;
+ }
+ entryMap[$(row).attr('data-entryname')].replaceWith(row);
+ });
+ });
+}
diff --git a/web_src/js/index.js b/web_src/js/index.js
index 4fda303a3c..d6787e89bf 100644
--- a/web_src/js/index.js
+++ b/web_src/js/index.js
@@ -20,6 +20,7 @@ import initTableSort from './features/tablesort.js';
import {createCodeEditor, createMonaco} from './features/codeeditor.js';
import {initMarkupAnchors} from './markup/anchors.js';
import {initNotificationsTable, initNotificationCount} from './features/notification.js';
+import {initLastCommitLoader} from './features/lastcommitloader.js';
import {initStopwatch} from './features/stopwatch.js';
import {showLineButton} from './code/linebutton.js';
import {initMarkupContent, initCommentContent} from './markup/content.js';
@@ -2864,6 +2865,7 @@ $(document).ready(async () => {
initContextPopups();
initTableSort();
initNotificationsTable();
+ initLastCommitLoader();
initPullRequestMergeInstruction();
initFileViewToggle();
initReleaseEditor();