diff options
author | Gusted <williamzijl7@hotmail.com> | 2022-04-26 20:34:30 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-26 16:34:30 -0400 |
commit | 076eaad7430dd80f202446487c99e95e8d803ab3 (patch) | |
tree | 6947ade9f26ffba8a23e384f7ad99562acd03f22 /web_src | |
parent | 89eec15dd90e50c36051eb3f6a2ed2616c513ad8 (diff) | |
download | gitea-076eaad7430dd80f202446487c99e95e8d803ab3.tar.gz gitea-076eaad7430dd80f202446487c99e95e8d803ab3.zip |
Improve dashboard's repo list performance (#18963)
* Improve dashboard's repo list performance
- Avoid a lot of database lookups for all the repo's, by adding a
undocumented "minimal" mode for this specific task, which returns the
data that's only needed by this list which doesn't require any database
lookups.
- Makes fetching these list faster.
- Less CPU overhead when a user visits home page.
* Refactor javascript code + fix Fork icon
- Use async in the function so we can use `await`.
- Remove `archivedFilter` check for count, as it doesn't make sense to
show the count of repos when you can't even see them(as they are
filited away).
* Add `count_only`
* Remove uncessary code
* Improve comment
Co-authored-by: delvh <dev.lh@web.de>
* Update web_src/js/components/DashboardRepoList.js
Co-authored-by: delvh <dev.lh@web.de>
* Update web_src/js/components/DashboardRepoList.js
Co-authored-by: delvh <dev.lh@web.de>
* By default apply minimal mode
* Remove `minimal` paramater
* Refactor count header
* Simplify init
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: delvh <dev.lh@web.de>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'web_src')
-rw-r--r-- | web_src/js/components/DashboardRepoList.js | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/web_src/js/components/DashboardRepoList.js b/web_src/js/components/DashboardRepoList.js index e4847ec2f0..36caaf2f5b 100644 --- a/web_src/js/components/DashboardRepoList.js +++ b/web_src/js/components/DashboardRepoList.js @@ -298,36 +298,41 @@ function initVueComponents() { this.searchRepos(); }, - searchRepos() { + async searchRepos() { this.isLoading = true; - if (!this.reposTotalCount) { - const totalCountSearchURL = `${this.subUrl}/repo/search?sort=updated&order=desc&uid=${this.uid}&team_id=${this.teamId}&q=&page=1&mode=`; - $.getJSON(totalCountSearchURL, (_result, _textStatus, request) => { - this.reposTotalCount = request.getResponseHeader('X-Total-Count'); - }); - } - const searchedMode = this.repoTypes[this.reposFilter].searchMode; const searchedURL = this.searchURL; const searchedQuery = this.searchQuery; - $.getJSON(searchedURL, (result, _textStatus, request) => { - if (searchedURL === this.searchURL) { - this.repos = result.data; - const count = request.getResponseHeader('X-Total-Count'); - if (searchedQuery === '' && searchedMode === '' && this.archivedFilter === 'both') { - this.reposTotalCount = count; - } - Vue.set(this.counts, `${this.reposFilter}:${this.archivedFilter}:${this.privateFilter}`, count); - this.finalPage = Math.ceil(count / this.searchLimit); - this.updateHistory(); + let response, json; + try { + if (!this.reposTotalCount) { + const totalCountSearchURL = `${this.subUrl}/repo/search?count_only=1&uid=${this.uid}&team_id=${this.teamId}&q=&page=1&mode=`; + response = await fetch(totalCountSearchURL); + this.reposTotalCount = response.headers.get('X-Total-Count'); } - }).always(() => { + + response = await fetch(searchedURL); + json = await response.json(); + } catch { if (searchedURL === this.searchURL) { this.isLoading = false; } - }); + return; + } + + if (searchedURL === this.searchURL) { + this.repos = json.data; + const count = response.headers.get('X-Total-Count'); + if (searchedQuery === '' && searchedMode === '' && this.archivedFilter === 'both') { + this.reposTotalCount = count; + } + Vue.set(this.counts, `${this.reposFilter}:${this.archivedFilter}:${this.privateFilter}`, count); + this.finalPage = Math.ceil(count / this.searchLimit); + this.updateHistory(); + this.isLoading = false; + } }, repoIcon(repo) { |