From 1be4a8e75aeaecba44965a744b95125d467122be Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Tue, 5 Dec 2023 16:17:17 +0800 Subject: [PATCH] * Adjust svn dir load speed. --- lib/scm/subversion.class.php | 7 +++-- module/repo/control.php | 43 +++++++++++++++++----------- module/repo/js/browse.ui.js | 2 +- module/repo/ui/monaco.html.php | 9 ------ module/repo/zen.php | 52 ++++++++++++++++++++++++++++++++-- 5 files changed, 81 insertions(+), 32 deletions(-) diff --git a/lib/scm/subversion.class.php b/lib/scm/subversion.class.php index 1ef418e461..a7a693a742 100644 --- a/lib/scm/subversion.class.php +++ b/lib/scm/subversion.class.php @@ -75,14 +75,17 @@ class Subversion foreach($listObject as $list) { $info = new stdclass(); + $info->size = 0; $info->name = (string)$list->name; + $info->path = $resourcePath . '/' . $list->name; $info->kind = (string)$list['kind']; $info->revision = (int)$list->commit['revision']; $info->account = (string)$list->commit->author; $info->date = date('Y-m-d H:i:s', strtotime($list->commit->date)); - $info->size = $info->kind == 'file' ? (int)$list->size > 1024 ? round((int)$list->size / 1024, 2) . "KB" : (int)$list->size . 'Bytes' : 0; $info->comment = ''; - $infos[] = $info; + + if($info->kind == 'file') $info->size = (int)$list->size > 1024 ? round((int)$list->size / 1024, 2) . "KB" : (int)$list->size . 'Bytes'; + $infos[] = $info; } /* Sort by kind */ diff --git a/module/repo/control.php b/module/repo/control.php index ce27beeeea..87ccd6c646 100644 --- a/module/repo/control.php +++ b/module/repo/control.php @@ -320,26 +320,31 @@ class repo extends control $this->commonAction($repoID, $objectID); $file = $entry; - $repo = $this->repo->getByID($repoID); $entry = $this->repo->decodePath($entry); $entry = urldecode($entry); $pathInfo = helper::mbPathinfo($entry); + $repo = $this->repo->getByID($repoID); if($repo->SCM == 'Gitlab') $repo = $this->repo->processGitService($repo, true); + + $dropMenus = array(); + if(in_array($repo->SCM, $this->config->repo->gitTypeList)) $dropMenus = $this->repoZen->getBranchAndTagItems($repo, $this->cookie->repoBranch); + if($this->app->tab == 'execution') $this->view->executionID = $objectID; - $this->view->title = $this->lang->repo->common . $this->lang->colon . $this->lang->repo->view; - $this->view->dropMenus = $this->repoZen->getBranchAndTagItems($repo, $this->cookie->repoBranch); - $this->view->type = 'view'; - $this->view->branchID = $this->cookie->repoBranch; - $this->view->showBug = $showBug; - $this->view->encoding = $encoding; - $this->view->repoID = $repoID; - $this->view->objectID = $objectID; - $this->view->repo = $repo; - $this->view->revision = $revision; - $this->view->file = $file; - $this->view->entry = $entry; - $this->view->pathInfo = $pathInfo; + $this->view->title = $this->lang->repo->common . $this->lang->colon . $this->lang->repo->view; + $this->view->dropMenus = $dropMenus; + $this->view->type = 'view'; + $this->view->branchID = $this->cookie->repoBranch; + $this->view->showBug = $showBug; + $this->view->encoding = $encoding; + $this->view->repoID = $repoID; + $this->view->objectID = $objectID; + $this->view->repo = $repo; + $this->view->revision = $revision; + $this->view->file = $file; + $this->view->entry = $entry; + $this->view->pathInfo = $pathInfo; + $this->view->tree = $this->repoZen->getViewTree($repo, '', $revision); $this->display(); } @@ -1566,7 +1571,9 @@ class repo extends control { $repo = $this->repo->getByID($repoID); if($path) $path = helper::safe64Decode($path); - echo json_encode($this->repo->getGitlabFilesByPath($repo, $path, $branch)); + + if($repo->SCM == 'gitlab') return print(json_encode($this->repo->getGitlabFilesByPath($repo, $path, $branch))); + return print(json_encode($this->repoZen->getViewTree($repo, $path, $branch))); } /** @@ -1578,7 +1585,9 @@ class repo extends control */ public function ajaxGetFileCommitInfo() { - $repo = $this->repo->getByID((int)$this->post->repoID); - echo json_encode($this->loadModel('gitlab')->getFileLastCommit($repo, $this->post->path, $this->post->branch)); + $repo = $this->repo->getByID((int)$this->post->repoID); + $commit = $this->loadModel('gitlab')->getFileLastCommit($repo, $this->post->path, $this->post->branch); + $commit->comment = $this->repo->replaceCommentLink($commit->message); + echo json_encode($commit); } } diff --git a/module/repo/js/browse.ui.js b/module/repo/js/browse.ui.js index 809ee2a17b..fb7c2d1d3c 100644 --- a/module/repo/js/browse.ui.js +++ b/module/repo/js/browse.ui.js @@ -59,7 +59,7 @@ window.afterRender = function() // 合并行数据和提交信息 oldData[nextCommitRowIndex].date = commit.authoredDate; oldData[nextCommitRowIndex].account = commit.author ? commit.author.username : commit.authorName; - oldData[nextCommitRowIndex].comment = commit.message; + oldData[nextCommitRowIndex].comment = commit.comment; oldData[nextCommitRowIndex].revision = commit.sha; // 重新渲染表格 diff --git a/module/repo/ui/monaco.html.php b/module/repo/ui/monaco.html.php index d47201f820..460b4fae12 100644 --- a/module/repo/ui/monaco.html.php +++ b/module/repo/ui/monaco.html.php @@ -20,15 +20,6 @@ dropmenu set::url(createLink($module, 'ajaxGetDropMenu', "objectID=$objectID&module={$app->rawModule}&method={$app->rawMethod}")) ); -if($repo->SCM == 'Gitlab') -{ - $tree = $this->repo->getGitlabFilesByPath($repo, '', (string)$branchID); -} -else -{ - $tree = $this->repo->getFileTree($repo); -} - jsVar('isonlybody', isonlybody()); jsVar('entry', $entry); jsVar('repoID', $repoID); diff --git a/module/repo/zen.php b/module/repo/zen.php index 24f4a876e4..abd2a99541 100644 --- a/module/repo/zen.php +++ b/module/repo/zen.php @@ -610,7 +610,6 @@ class repoZen extends repo if($repo->SCM == 'Gitlab') { $_COOKIE['repoBranch'] = $branchID ? $branchID : $this->cookie->repoBranch; - $infos = $this->repo->getGitlabFilesByPath($repo, $path, $branchID); foreach($infos as &$file) { @@ -625,19 +624,33 @@ class repoZen extends repo $infos = $this->repo->getFileCommits($repo, $branchID, $path); } + $filePath = $path; + if($repo->SCM == 'Subversion') + { + $scm = $this->app->loadClass('scm'); + $scm->setEngine($repo); + $info = $scm->info(''); + if(!empty($info->root)) + { + $prefixPath = str_replace($info->root . '/', '', $repo->path); + $filePath = trim(str_replace($prefixPath, '', $path), '/'); + } + } + foreach($infos as $info) { $info->originalComment = $info->comment; $info->comment = $this->repo->replaceCommentLink($info->comment); - $info->revision = $repo->SCM == 'Subversion' ? $info->revision : substr($info->revision, 0, 10); + if($repo->SCM != 'Subversion') $info->revision = substr($info->revision, 0, 10); - $infoPath = trim(urldecode($path) . '/' . $info->name, '/'); + $infoPath = trim(urldecode($path) . '/' . $info->name, '/'); if($info->kind == 'dir') { $info->link = $this->repo->createLink('browse', "repoID={$repo->id}&branchID=$base64BranchID&objectID=$objectID&path=" . $this->repo->encodePath($infoPath)); } else { + if($repo->SCM == 'Subversion') $infoPath = $filePath . '/' . $info->name; $info->link = $this->repo->createLink('view', "repoID={$repo->id}&objectID=$objectID&entry=" . $this->repo->encodePath($infoPath)); } } @@ -1465,4 +1478,37 @@ class repoZen extends repo return false; } + + /** + * 获取详情页面目录树。 + * Get view tree. + * + * @param object $repo + * @param string $entry + * @param string $revision + * @access protected + * @return array + */ + protected function getViewTree(object $repo, string $entry, string $revision): array + { + if($repo->SCM == 'Gitlab') return $this->repo->getGitlabFilesByPath($repo, '', (string)$this->cookie->repoBranch); + + if($repo->SCM != 'Subversion') return $this->repo->getFileTree($repo); + + $scm = $this->app->loadClass('scm'); + $scm->setEngine($repo); + $tree = $scm->ls($entry, (string)$revision); + foreach($tree as &$file) + { + $base64Name = base64_encode($file->path); + + $file->path = trim($file->path, '/'); + if(!isset($file->id)) $file->id = $base64Name; + if(!isset($file->key)) $file->key = $base64Name; + if(!isset($file->text)) $file->text = trim($file->name, '/'); + if($file->kind == 'dir') $file->items = array('url' => helper::createLink('repo', 'ajaxGetFiles', "repoID={$repo->id}&branch={$revision}&path=" . helper::safe64Encode($file->path))); + } + + return $tree; + } }