loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add ONLY_SHOW_RELEVANT_REPOS back, fix explore page bug, make code more strict (#23766)

Follow #21962

After I eat my own dogfood, I would say that
ONLY_SHOW_RELEVANT_REPOS=false is necessary for many private/enterprise
instances, because many private repositories do not have
"description/topic", users just want to search by their names.

This PR also adds `PageIsExploreRepositories` check, to make code more
strict, because the `search` template is shared for different purpose.

And during the test, I found a bug that the "Search" button didn't
respect the "relevant" parameter, so this PR fixes the bug by the way
together.

I think this PR needs to be backported.

authored by

wxiaoguang and committed by
GitHub
e57e1144 ed5e7d03

+26 -6
+4
custom/conf/app.example.ini
··· 1238 1238 ;; 1239 1239 ;; Whether to enable a Service Worker to cache frontend assets 1240 1240 ;USE_SERVICE_WORKER = false 1241 + ;; 1242 + ;; Whether to only show relevant repos on the explore page when no keyword is specified and default sorting is used. 1243 + ;; A repo is considered irrelevant if it's a fork or if it has no metadata (no description, no icon, no topic). 1244 + ;ONLY_SHOW_RELEVANT_REPOS = false 1241 1245 1242 1246 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1243 1247 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+3 -1
docs/content/doc/administration/config-cheat-sheet.en-us.md
··· 226 226 Values can be emoji alias (:smile:) or a unicode emoji. 227 227 For custom reactions, add a tightly cropped square image to public/img/emoji/reaction_name.png 228 228 - `CUSTOM_EMOJIS`: **gitea, codeberg, gitlab, git, github, gogs**: Additional Emojis not defined in the utf8 standard. 229 - By default we support Gitea (:gitea:), to add more copy them to public/img/emoji/emoji_name.png and 229 + By default, we support Gitea (:gitea:), to add more copy them to public/img/emoji/emoji_name.png and 230 230 add it to this config. 231 231 - `DEFAULT_SHOW_FULL_NAME`: **false**: Whether the full name of the users should be shown where possible. If the full name isn't set, the username will be used. 232 232 - `SEARCH_REPO_DESCRIPTION`: **true**: Whether to search within description at repository search on explore page. 233 233 - `USE_SERVICE_WORKER`: **false**: Whether to enable a Service Worker to cache frontend assets. 234 + - `ONLY_SHOW_RELEVANT_REPOS`: **false** Whether to only show relevant repos on the explore page when no keyword is specified and default sorting is used. 235 + A repo is considered irrelevant if it's a fork or if it has no metadata (no description, no icon, no topic). 234 236 235 237 ### UI - Admin (`ui.admin`) 236 238
+3
modules/setting/ui.go
··· 139 139 UI.DefaultShowFullName = sec.Key("DEFAULT_SHOW_FULL_NAME").MustBool(false) 140 140 UI.SearchRepoDescription = sec.Key("SEARCH_REPO_DESCRIPTION").MustBool(true) 141 141 UI.UseServiceWorker = sec.Key("USE_SERVICE_WORKER").MustBool(false) 142 + 143 + // OnlyShowRelevantRepos=false is important for many private/enterprise instances, 144 + // because many private repositories do not have "description/topic", users just want to search by their names. 142 145 UI.OnlyShowRelevantRepos = sec.Key("ONLY_SHOW_RELEVANT_REPOS").MustBool(false) 143 146 144 147 UI.ReactionsLookup = make(container.Set[string])
+11 -3
routers/web/explore/repo.go
··· 4 4 package explore 5 5 6 6 import ( 7 + "fmt" 7 8 "net/http" 8 9 9 10 "code.gitea.io/gitea/models/db" ··· 18 19 const ( 19 20 // tplExploreRepos explore repositories page template 20 21 tplExploreRepos base.TplName = "explore/repos" 21 - relevantReposOnlyParam string = "no_filter" 22 + relevantReposOnlyParam string = "only_show_relevant" 22 23 ) 23 24 24 25 // RepoSearchOptions when calling search repositories ··· 137 138 pager.SetDefaultParams(ctx) 138 139 pager.AddParam(ctx, "topic", "TopicOnly") 139 140 pager.AddParam(ctx, "language", "Language") 140 - pager.AddParamString(relevantReposOnlyParam, ctx.FormString(relevantReposOnlyParam)) 141 + pager.AddParamString(relevantReposOnlyParam, fmt.Sprint(opts.OnlyShowRelevant)) 141 142 ctx.Data["Page"] = pager 142 143 143 144 ctx.HTML(http.StatusOK, opts.TplName) ··· 156 157 ownerID = ctx.Doer.ID 157 158 } 158 159 160 + onlyShowRelevant := setting.UI.OnlyShowRelevantRepos 161 + 162 + _ = ctx.Req.ParseForm() // parse the form first, to prepare the ctx.Req.Form field 163 + if len(ctx.Req.Form[relevantReposOnlyParam]) != 0 { 164 + onlyShowRelevant = ctx.FormBool(relevantReposOnlyParam) 165 + } 166 + 159 167 RenderRepoSearch(ctx, &RepoSearchOptions{ 160 168 PageSize: setting.UI.ExplorePagingNum, 161 169 OwnerID: ownerID, 162 170 Private: ctx.Doer != nil, 163 171 TplName: tplExploreRepos, 164 - OnlyShowRelevant: !ctx.FormBool(relevantReposOnlyParam), 172 + OnlyShowRelevant: onlyShowRelevant, 165 173 }) 166 174 }
+5 -2
templates/explore/repo_search.tmpl
··· 26 26 <input type="hidden" name="language" value="{{$.Language}}"> 27 27 <div class="ui fluid action input"> 28 28 <input name="q" value="{{.Keyword}}" placeholder="{{.locale.Tr "explore.search"}}…" autofocus> 29 + {{if .PageIsExploreRepositories}} 30 + <input type="hidden" name="only_show_relevant" value="{{.OnlyShowRelevant}}"> 31 + {{end}} 29 32 <button class="ui primary button">{{.locale.Tr "explore.search"}}</button> 30 33 </div> 31 34 </form> 32 - {{if .OnlyShowRelevant}} 35 + {{if and .PageIsExploreRepositories .OnlyShowRelevant}} 33 36 <div class="ui message explore-relevancy-note"> 34 - <span data-tooltip-content="{{.locale.Tr "explore.relevant_repositories_tooltip"}}">{{.locale.Tr "explore.relevant_repositories" ((printf "%s%s" $.Link "?no_filter=1")|Escape) | Safe}}</span> 37 + <span data-tooltip-content="{{.locale.Tr "explore.relevant_repositories_tooltip"}}">{{.locale.Tr "explore.relevant_repositories" ((printf "%s%s" $.Link "?only_show_relevant=0")|Escape) | Safe}}</span> 35 38 </div> 36 39 {{end}} 37 40 <div class="ui divider"></div>