2022-05-16 22:15:12 +05:30
|
|
|
<div class="ui attached table segment commit-table">
|
|
|
|
<table class="ui very basic striped table unstackable fixed" id="commits-table">
|
2019-11-02 03:32:41 +05:30
|
|
|
<thead>
|
|
|
|
<tr>
|
2022-10-25 22:30:37 +05:30
|
|
|
<th class="three wide">{{.locale.Tr "repo.commits.author"}}</th>
|
2019-11-02 03:32:41 +05:30
|
|
|
<th class="two wide sha">SHA1</th>
|
2022-10-25 22:30:37 +05:30
|
|
|
<th class="nine wide message">{{.locale.Tr "repo.commits.message"}}</th>
|
|
|
|
<th class="two wide right aligned">{{.locale.Tr "repo.commits.date"}}</th>
|
2019-11-02 03:32:41 +05:30
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody class="commit-list">
|
2022-01-18 21:42:10 +05:30
|
|
|
{{$commitRepoLink := $.RepoLink}}{{if $.CommitRepoLink}}{{$commitRepoLink = $.CommitRepoLink}}{{end}}
|
2021-08-09 23:38:51 +05:30
|
|
|
{{range .Commits}}
|
2019-11-02 03:32:41 +05:30
|
|
|
<tr>
|
|
|
|
<td class="author">
|
2019-11-04 15:50:12 +05:30
|
|
|
{{$userName := .Author.Name}}
|
2019-11-02 03:32:41 +05:30
|
|
|
{{if .User}}
|
|
|
|
{{if .User.FullName}}
|
2019-11-04 15:50:12 +05:30
|
|
|
{{$userName = .User.FullName}}
|
2019-11-02 03:32:41 +05:30
|
|
|
{{end}}
|
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 19:07:34 +05:30
|
|
|
{{avatar $.Context .User 28 "gt-mr-2"}}<a href="{{.User.HomeLink}}">{{$userName}}</a>
|
2019-11-02 03:32:41 +05:30
|
|
|
{{else}}
|
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 19:07:34 +05:30
|
|
|
{{avatarByEmail $.Context .Author.Email .Author.Name 28 "gt-mr-2"}}
|
2020-12-04 00:16:11 +05:30
|
|
|
{{$userName}}
|
2019-11-02 03:32:41 +05:30
|
|
|
{{end}}
|
|
|
|
</td>
|
2023-02-13 23:29:59 +05:30
|
|
|
<td class="sha gt-df">
|
|
|
|
<button class="ui button copy-commit-sha gt-df gt-ac" data-clipboard-text="{{.ID}}">{{svg "octicon-copy" 14}}</button>
|
2019-11-04 15:50:12 +05:30
|
|
|
{{$class := "ui sha label"}}
|
|
|
|
{{if .Signature}}
|
|
|
|
{{$class = (printf "%s%s" $class " isSigned")}}
|
|
|
|
{{if .Verification.Verified}}
|
2020-02-28 00:50:55 +05:30
|
|
|
{{if eq .Verification.TrustStatus "trusted"}}
|
|
|
|
{{$class = (printf "%s%s" $class " isVerified")}}
|
|
|
|
{{else if eq .Verification.TrustStatus "untrusted"}}
|
|
|
|
{{$class = (printf "%s%s" $class " isVerifiedUntrusted")}}
|
|
|
|
{{else}}
|
|
|
|
{{$class = (printf "%s%s" $class " isVerifiedUnmatched")}}
|
|
|
|
{{end}}
|
2019-11-04 15:50:12 +05:30
|
|
|
{{else if .Verification.Warning}}
|
|
|
|
{{$class = (printf "%s%s" $class " isWarning")}}
|
|
|
|
{{end}}
|
|
|
|
{{end}}
|
2020-05-16 22:08:40 +05:30
|
|
|
{{if $.PageIsWiki}}
|
2022-01-18 21:42:10 +05:30
|
|
|
<a href="{{$commitRepoLink}}/wiki/commit/{{.ID}}" rel="nofollow" class="{{$class}}">
|
2020-05-16 22:08:40 +05:30
|
|
|
{{else if $.Reponame}}
|
2022-01-18 21:42:10 +05:30
|
|
|
<a href="{{$commitRepoLink}}/commit/{{.ID}}" rel="nofollow" class="{{$class}}">
|
2019-11-04 15:50:12 +05:30
|
|
|
{{else}}
|
|
|
|
<span class="{{$class}}">
|
|
|
|
{{end}}
|
2020-02-28 00:50:55 +05:30
|
|
|
<span class="shortsha">{{ShortSha .ID.String}}</span>
|
2019-11-02 03:32:41 +05:30
|
|
|
{{if .Signature}}
|
2020-06-03 05:52:26 +05:30
|
|
|
{{template "repo/shabox_badge" dict "root" $ "verification" .Verification}}
|
2019-11-02 03:32:41 +05:30
|
|
|
{{end}}
|
2019-11-04 15:50:12 +05:30
|
|
|
{{if $.Reponame}}
|
|
|
|
</a>
|
|
|
|
{{else}}
|
|
|
|
</span>
|
|
|
|
{{end}}
|
2019-11-02 03:32:41 +05:30
|
|
|
</td>
|
|
|
|
<td class="message">
|
|
|
|
<span class="message-wrapper">
|
2019-12-03 23:45:41 +05:30
|
|
|
{{if $.PageIsWiki}}
|
2020-05-01 23:28:45 +05:30
|
|
|
<span class="commit-summary {{if gt .ParentCount 1}} grey text{{end}}" title="{{.Summary}}">{{.Summary | RenderEmoji}}</span>
|
2022-08-26 03:25:52 +05:30
|
|
|
{{else}}
|
|
|
|
{{$commitLink:= printf "%s/commit/%s" $commitRepoLink (PathEscape .ID.String)}}
|
2022-01-20 04:56:57 +05:30
|
|
|
<span class="commit-summary {{if gt .ParentCount 1}} grey text{{end}}" title="{{.Summary}}">{{RenderCommitMessageLinkSubject $.Context .Message $commitRepoLink $commitLink $.Repository.ComposeMetas}}</span>
|
2019-12-03 23:45:41 +05:30
|
|
|
{{end}}
|
2019-11-02 03:32:41 +05:30
|
|
|
</span>
|
|
|
|
{{if IsMultilineCommitMessage .Message}}
|
2021-11-23 08:14:38 +05:30
|
|
|
<button class="ui button ellipsis-button" aria-expanded="false">...</button>
|
2019-11-02 03:32:41 +05:30
|
|
|
{{end}}
|
2021-08-09 23:38:51 +05:30
|
|
|
{{template "repo/commit_statuses" dict "Status" .Status "Statuses" .Statuses "root" $}}
|
2019-11-02 03:32:41 +05:30
|
|
|
{{if IsMultilineCommitMessage .Message}}
|
2022-01-20 04:56:57 +05:30
|
|
|
<pre class="commit-body" style="display: none;">{{RenderCommitBody $.Context .Message $commitRepoLink $.Repository.ComposeMetas}}</pre>
|
2019-11-02 03:32:41 +05:30
|
|
|
{{end}}
|
|
|
|
</td>
|
2022-01-25 03:41:40 +05:30
|
|
|
{{if .Committer}}
|
2022-06-28 02:28:46 +05:30
|
|
|
<td class="text right aligned">{{TimeSince .Committer.When $.locale}}</td>
|
2022-01-25 03:41:40 +05:30
|
|
|
{{else}}
|
2022-06-28 02:28:46 +05:30
|
|
|
<td class="text right aligned">{{TimeSince .Author.When $.locale}}</td>
|
2022-01-25 03:41:40 +05:30
|
|
|
{{end}}
|
2019-11-02 03:32:41 +05:30
|
|
|
</tr>
|
|
|
|
{{end}}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|