2015-11-22 14:32:09 +08:00
|
|
|
{{template "base/head" .}}
|
2023-02-02 06:56:10 +08:00
|
|
|
<div role="main" aria-label="{{.Title}}" class="page-content organization profile">
|
2023-02-14 01:59:59 +08:00
|
|
|
<div class="ui container gt-df">
|
Add context cache as a request level cache (#22294)
To avoid duplicated load of the same data in an HTTP request, we can set
a context cache to do that. i.e. Some pages may load a user from a
database with the same id in different areas on the same page. But the
code is hidden in two different deep logic. How should we share the
user? As a result of this PR, now if both entry functions accept
`context.Context` as the first parameter and we just need to refactor
`GetUserByID` to reuse the user from the context cache. Then it will not
be loaded twice on an HTTP request.
But of course, sometimes we would like to reload an object from the
database, that's why `RemoveContextData` is also exposed.
The core context cache is here. It defines a new context
```go
type cacheContext struct {
ctx context.Context
data map[any]map[any]any
lock sync.RWMutex
}
var cacheContextKey = struct{}{}
func WithCacheContext(ctx context.Context) context.Context {
return context.WithValue(ctx, cacheContextKey, &cacheContext{
ctx: ctx,
data: make(map[any]map[any]any),
})
}
```
Then you can use the below 4 methods to read/write/del the data within
the same context.
```go
func GetContextData(ctx context.Context, tp, key any) any
func SetContextData(ctx context.Context, tp, key, value any)
func RemoveContextData(ctx context.Context, tp, key any)
func GetWithContextCache[T any](ctx context.Context, cacheGroupKey string, cacheTargetID any, f func() (T, error)) (T, error)
```
Then let's take a look at how `system.GetString` implement it.
```go
func GetSetting(ctx context.Context, key string) (string, error) {
return cache.GetWithContextCache(ctx, contextCacheKey, key, func() (string, error) {
return cache.GetString(genSettingCacheKey(key), func() (string, error) {
res, err := GetSettingNoCache(ctx, key)
if err != nil {
return "", err
}
return res.SettingValue, nil
})
})
}
```
First, it will check if context data include the setting object with the
key. If not, it will query from the global cache which may be memory or
a Redis cache. If not, it will get the object from the database. In the
end, if the object gets from the global cache or database, it will be
set into the context cache.
An object stored in the context cache will only be destroyed after the
context disappeared.
2023-02-15 21:37:34 +08:00
|
|
|
{{avatar $.Context .Org 140 "org-avatar"}}
|
2018-01-10 07:11:01 +08:00
|
|
|
<div id="org-info">
|
2023-05-11 06:27:02 +08:00
|
|
|
<div class="ui header gt-df gt-fw">
|
2018-01-10 07:11:01 +08:00
|
|
|
{{.Org.DisplayName}}
|
2020-10-06 14:25:43 +08:00
|
|
|
<span class="org-visibility">
|
2023-05-11 06:27:02 +08:00
|
|
|
{{if .Org.Visibility.IsLimited}}<span class="ui large basic horizontal label">{{.locale.Tr "org.settings.visibility.limited_shortname"}}</span>{{end}}
|
|
|
|
{{if .Org.Visibility.IsPrivate}}<span class="ui large basic horizontal label">{{.locale.Tr "org.settings.visibility.private_shortname"}}</span>{{end}}
|
2020-10-06 14:25:43 +08:00
|
|
|
</span>
|
2023-05-11 06:27:02 +08:00
|
|
|
{{if .EnableFeed}}
|
2023-05-12 18:23:53 +08:00
|
|
|
<a class="rss-icon gt-mx-3" href="{{.Org.HomeLink}}.rss" data-tooltip-content="{{.locale.Tr "rss_feed"}}">{{svg "octicon-rss" 24}}</a>
|
2023-05-11 06:27:02 +08:00
|
|
|
{{end}}
|
2018-01-10 07:11:01 +08:00
|
|
|
</div>
|
2023-01-30 16:16:12 +08:00
|
|
|
{{if $.RenderedDescription}}<div class="render-content markup">{{$.RenderedDescription|Str2html}}</div>{{end}}
|
2018-01-10 07:11:01 +08:00
|
|
|
<div class="text grey meta">
|
2023-07-25 16:26:27 +08:00
|
|
|
{{if .Org.Location}}<div class="flex-text-block">{{svg "octicon-location"}} <span>{{.Org.Location}}</span></div>{{end}}
|
|
|
|
{{if .Org.Website}}<div class="flex-text-block">{{svg "octicon-link"}} <a target="_blank" rel="noopener noreferrer me" href="{{.Org.Website}}">{{.Org.Website}}</a></div>{{end}}
|
|
|
|
{{if $.IsSigned}}
|
|
|
|
{{if .Org.Email}}<div class="flex-text-block">{{svg "octicon-mail"}} <a class="muted" href="mailto:{{.Org.Email}}">{{.Org.Email}}</a></div>{{end}}
|
|
|
|
{{end}}
|
2015-12-08 06:30:52 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-06-09 17:10:51 +08:00
|
|
|
<div class="right menu">
|
2023-07-07 23:27:12 +08:00
|
|
|
<button class="link-action ui basic button gt-mr-0" data-url="{{.Org.HomeLink}}?action={{if $.IsFollowing}}unfollow{{else}}follow{{end}}">
|
|
|
|
{{if $.IsFollowing}}
|
|
|
|
{{.locale.Tr "user.unfollow"}}
|
|
|
|
{{else}}
|
|
|
|
{{.locale.Tr "user.follow"}}
|
|
|
|
{{end}}
|
|
|
|
</button>
|
2023-04-30 03:13:58 +08:00
|
|
|
</div>
|
2015-12-08 06:30:52 +08:00
|
|
|
</div>
|
2015-11-22 14:32:09 +08:00
|
|
|
|
2021-11-25 00:12:54 +08:00
|
|
|
{{template "org/menu" .}}
|
2015-11-22 14:32:09 +08:00
|
|
|
|
2015-12-08 06:30:52 +08:00
|
|
|
<div class="ui container">
|
2018-01-10 07:11:01 +08:00
|
|
|
<div class="ui mobile reversed stackable grid">
|
2015-12-08 06:30:52 +08:00
|
|
|
<div class="ui eleven wide column">
|
2019-02-09 00:45:43 +08:00
|
|
|
{{template "explore/repo_search" .}}
|
2015-12-08 06:30:52 +08:00
|
|
|
{{template "explore/repo_list" .}}
|
2016-11-07 18:44:49 +08:00
|
|
|
{{template "base/paginate" .}}
|
2015-12-08 06:30:52 +08:00
|
|
|
</div>
|
2015-11-22 14:32:09 +08:00
|
|
|
|
2015-12-08 06:30:52 +08:00
|
|
|
<div class="ui five wide column">
|
2022-02-19 20:08:12 +08:00
|
|
|
{{if .CanCreateOrgRepo}}
|
|
|
|
<div class="center aligned">
|
2022-06-28 04:58:46 +08:00
|
|
|
<a class="ui green button" href="{{AppSubUrl}}/repo/create?org={{.Org.ID}}">{{.locale.Tr "new_repo"}}</a>
|
2022-02-19 20:08:12 +08:00
|
|
|
{{if not .DisableNewPullMirrors}}
|
2022-06-28 04:58:46 +08:00
|
|
|
<a class="ui green button" href="{{AppSubUrl}}/repo/migrate?org={{.Org.ID}}&mirror=1">{{.locale.Tr "new_migrate"}}</a>
|
2022-02-19 20:08:12 +08:00
|
|
|
{{end}}
|
|
|
|
</div>
|
2023-06-29 20:24:22 +08:00
|
|
|
<div class="divider"></div>
|
2022-02-19 20:08:12 +08:00
|
|
|
{{end}}
|
2023-02-14 01:59:59 +08:00
|
|
|
<h4 class="ui top attached header gt-df">
|
2023-02-18 21:41:31 +08:00
|
|
|
<strong class="gt-f1">{{.locale.Tr "org.members"}}</strong>
|
2023-03-24 18:35:38 +08:00
|
|
|
<a class="text grey gt-dif gt-ac" href="{{.OrgLink}}/members"><span>{{.MembersTotal}}</span> {{svg "octicon-chevron-right"}}</a>
|
2015-12-08 06:30:52 +08:00
|
|
|
</h4>
|
|
|
|
<div class="ui attached segment members">
|
|
|
|
{{$isMember := .IsOrganizationMember}}
|
|
|
|
{{range .Members}}
|
2021-11-22 23:21:55 +08:00
|
|
|
{{if or $isMember (call $.IsPublicMember .ID)}}
|
2023-04-04 12:49:09 +08:00
|
|
|
<a href="{{.HomeLink}}" title="{{.Name}}{{if .FullName}} ({{.FullName}}){{end}}">{{avatar $.Context . 48}}</a>
|
2015-12-08 06:30:52 +08:00
|
|
|
{{end}}
|
|
|
|
{{end}}
|
|
|
|
</div>
|
2015-11-22 14:32:09 +08:00
|
|
|
|
2015-12-08 06:30:52 +08:00
|
|
|
{{if .IsOrganizationMember}}
|
2023-02-14 01:59:59 +08:00
|
|
|
<div class="ui top attached header gt-df">
|
|
|
|
<strong class="gt-f1">{{.locale.Tr "org.teams"}}</strong>
|
2023-03-24 18:35:38 +08:00
|
|
|
<a class="text grey gt-dif gt-ac" href="{{.OrgLink}}/teams"><span>{{.Org.NumTeams}}</span> {{svg "octicon-chevron-right"}}</a>
|
2015-12-08 06:30:52 +08:00
|
|
|
</div>
|
|
|
|
<div class="ui attached table segment teams">
|
|
|
|
{{range .Teams}}
|
|
|
|
<div class="item">
|
2021-11-17 02:18:25 +08:00
|
|
|
<a href="{{$.OrgLink}}/teams/{{.LowerName | PathEscape}}"><strong class="team-name">{{.Name}}</strong></a>
|
2017-11-04 13:46:34 +08:00
|
|
|
<p class="text grey">
|
2022-11-19 12:02:30 +08:00
|
|
|
<a class="muted" href="{{$.OrgLink}}/teams/{{.LowerName | PathEscape}}"><strong>{{.NumMembers}}</strong> {{$.locale.Tr "org.lower_members"}}</a> ·
|
|
|
|
<a class="muted" href="{{$.OrgLink}}/teams/{{.LowerName | PathEscape}}/repositories"><strong>{{.NumRepos}}</strong> {{$.locale.Tr "org.lower_repositories"}}</a>
|
2017-11-04 13:46:34 +08:00
|
|
|
</p>
|
2015-12-08 06:30:52 +08:00
|
|
|
</div>
|
|
|
|
{{end}}
|
|
|
|
</div>
|
|
|
|
{{if .IsOrganizationOwner}}
|
|
|
|
<div class="ui bottom attached segment">
|
2022-06-28 04:58:46 +08:00
|
|
|
<a class="ui primary small button" href="{{.OrgLink}}/teams/new">{{.locale.Tr "org.create_new_team"}}</a>
|
2015-12-08 06:30:52 +08:00
|
|
|
</div>
|
|
|
|
{{end}}
|
|
|
|
{{end}}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2014-06-29 03:43:25 +08:00
|
|
|
</div>
|
2015-12-08 06:30:52 +08:00
|
|
|
{{template "base/footer" .}}
|