aboutsummaryrefslogtreecommitdiffstats
path: root/modules/util
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2024-03-21 21:13:08 +0800
committerGitHub <noreply@github.com>2024-03-21 14:13:08 +0100
commit62f8174aa2fae1481c7e17a6afcb731a5b178cd0 (patch)
treef94686ea110e943418a25534e0306f45169c9f48 /modules/util
parent01500957c29f6bfa2396b8457dbb0645edaafa99 (diff)
downloadgitea-62f8174aa2fae1481c7e17a6afcb731a5b178cd0.tar.gz
gitea-62f8174aa2fae1481c7e17a6afcb731a5b178cd0.zip
Performance improvements for pull request list page (#29900)
This PR will avoid load pullrequest.Issue twice in pull request list page. It will reduce x times database queries for those WIP pull requests. Partially fix #29585 --------- Co-authored-by: Giteabot <teabot@gitea.io>
Diffstat (limited to 'modules/util')
-rw-r--r--modules/util/slice.go11
1 files changed, 10 insertions, 1 deletions
diff --git a/modules/util/slice.go b/modules/util/slice.go
index f00e84bf06..9c878c24be 100644
--- a/modules/util/slice.go
+++ b/modules/util/slice.go
@@ -54,7 +54,7 @@ func Sorted[S ~[]E, E cmp.Ordered](values S) S {
return values
}
-// TODO: Replace with "maps.Values" once available
+// TODO: Replace with "maps.Values" once available, current it only in golang.org/x/exp/maps but not in standard library
func ValuesOfMap[K comparable, V any](m map[K]V) []V {
values := make([]V, 0, len(m))
for _, v := range m {
@@ -62,3 +62,12 @@ func ValuesOfMap[K comparable, V any](m map[K]V) []V {
}
return values
}
+
+// TODO: Replace with "maps.Keys" once available, current it only in golang.org/x/exp/maps but not in standard library
+func KeysOfMap[K comparable, V any](m map[K]V) []K {
+ keys := make([]K, 0, len(m))
+ for k := range m {
+ keys = append(keys, k)
+ }
+ return keys
+}