Skip to content

Commit 50e6929

Browse files
authored
Merge branch 'main' into lunny/lock_per_package
2 parents 87c7405 + a581847 commit 50e6929

File tree

110 files changed

+7477
-4411
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+7477
-4411
lines changed

.github/ISSUE_TEMPLATE/bug-report.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ body:
1111
value: |
1212
1. Please speak English, this is the language all maintainers can speak and write.
1313
2. Please ask questions or configuration/deploy problems on our Discord
14-
server (https://discord.gg/gitea) or forum (https://discourse.gitea.io).
14+
server (https://discord.gg/gitea) or forum (https://forum.gitea.com).
1515
3. Make sure you are using the latest release and
1616
take a moment to check that your issue hasn't been reported before.
1717
4. Make sure it's not mentioned in the FAQ (https://docs.gitea.com/help/faq)

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ contact_links:
77
url: https://discord.gg/Gitea
88
about: Please ask questions and discuss configuration or deployment problems here.
99
- name: Discourse Forum
10-
url: https://discourse.gitea.io
10+
url: https://forum.gitea.com
1111
about: Questions and configuration or deployment problems can also be discussed on our forum.
1212
- name: Frequently Asked Questions
1313
url: https://docs.gitea.com/help/faq

.github/ISSUE_TEMPLATE/feature-request.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ body:
77
value: |
88
1. Please speak English, this is the language all maintainers can speak and write.
99
2. Please ask questions or configuration/deploy problems on our Discord
10-
server (https://discord.gg/gitea) or forum (https://discourse.gitea.io).
10+
server (https://discord.gg/gitea) or forum (https://forum.gitea.com).
1111
3. Please take a moment to check that your feature hasn't already been suggested.
1212
- type: textarea
1313
id: description

.github/ISSUE_TEMPLATE/ui.bug-report.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ body:
1111
value: |
1212
1. Please speak English, this is the language all maintainers can speak and write.
1313
2. Please ask questions or configuration/deploy problems on our Discord
14-
server (https://discord.gg/gitea) or forum (https://discourse.gitea.io).
14+
server (https://discord.gg/gitea) or forum (https://forum.gitea.com).
1515
3. Please take a moment to check that your issue doesn't already exist.
1616
4. Make sure it's not mentioned in the FAQ (https://docs.gitea.com/help/faq)
1717
5. Please give all relevant information below for bug reports, because

cmd/hook.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,22 @@ Gitea or set your environment appropriately.`, "")
290290
return nil
291291
}
292292

293+
// runHookUpdate avoid to do heavy operations on update hook because it will be
294+
// invoked for every ref update which does not like pre-receive and post-receive
293295
func runHookUpdate(c *cli.Context) error {
296+
if isInternal, _ := strconv.ParseBool(os.Getenv(repo_module.EnvIsInternal)); isInternal {
297+
return nil
298+
}
299+
294300
// Update is empty and is kept only for backwards compatibility
301+
if len(os.Args) < 3 {
302+
return nil
303+
}
304+
refName := git.RefName(os.Args[len(os.Args)-3])
305+
if refName.IsPull() {
306+
// ignore update to refs/pull/xxx/head, so we don't need to output any information
307+
os.Exit(1)
308+
}
295309
return nil
296310
}
297311

models/activities/action.go

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -450,17 +450,46 @@ func GetFeeds(ctx context.Context, opts GetFeedsOptions) (ActionList, int64, err
450450
return nil, 0, err
451451
}
452452

453-
sess := db.GetEngine(ctx).Where(cond).
454-
Select("`action`.*"). // this line will avoid select other joined table's columns
455-
Join("INNER", "repository", "`repository`.id = `action`.repo_id")
453+
actions := make([]*Action, 0, opts.PageSize)
454+
var count int64
456455

457-
opts.SetDefaultValues()
458-
sess = db.SetSessionPagination(sess, &opts)
456+
if opts.Page < 10 { // TODO: why it's 10 but other values? It's an experience value.
457+
sess := db.GetEngine(ctx).Where(cond).
458+
Select("`action`.*"). // this line will avoid select other joined table's columns
459+
Join("INNER", "repository", "`repository`.id = `action`.repo_id")
459460

460-
actions := make([]*Action, 0, opts.PageSize)
461-
count, err := sess.Desc("`action`.created_unix").FindAndCount(&actions)
462-
if err != nil {
463-
return nil, 0, fmt.Errorf("FindAndCount: %w", err)
461+
opts.SetDefaultValues()
462+
sess = db.SetSessionPagination(sess, &opts)
463+
464+
count, err = sess.Desc("`action`.created_unix").FindAndCount(&actions)
465+
if err != nil {
466+
return nil, 0, fmt.Errorf("FindAndCount: %w", err)
467+
}
468+
} else {
469+
// First, only query which IDs are necessary, and only then query all actions to speed up the overall query
470+
sess := db.GetEngine(ctx).Where(cond).
471+
Select("`action`.id").
472+
Join("INNER", "repository", "`repository`.id = `action`.repo_id")
473+
474+
opts.SetDefaultValues()
475+
sess = db.SetSessionPagination(sess, &opts)
476+
477+
actionIDs := make([]int64, 0, opts.PageSize)
478+
if err := sess.Table("action").Desc("`action`.created_unix").Find(&actionIDs); err != nil {
479+
return nil, 0, fmt.Errorf("Find(actionsIDs): %w", err)
480+
}
481+
482+
count, err = db.GetEngine(ctx).Where(cond).
483+
Table("action").
484+
Cols("`action`.id").
485+
Join("INNER", "repository", "`repository`.id = `action`.repo_id").Count()
486+
if err != nil {
487+
return nil, 0, fmt.Errorf("Count: %w", err)
488+
}
489+
490+
if err := db.GetEngine(ctx).In("`action`.id", actionIDs).Desc("`action`.created_unix").Find(&actions); err != nil {
491+
return nil, 0, fmt.Errorf("Find: %w", err)
492+
}
464493
}
465494

466495
if err := ActionList(actions).LoadAttributes(ctx); err != nil {

models/auth/access_token_scope.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,22 @@ func (s AccessTokenScope) HasScope(scopes ...AccessTokenScope) (bool, error) {
309309
return true, nil
310310
}
311311

312+
// HasAnyScope returns true if any of the scopes is contained in the string
313+
func (s AccessTokenScope) HasAnyScope(scopes ...AccessTokenScope) (bool, error) {
314+
bitmap, err := s.parse()
315+
if err != nil {
316+
return false, err
317+
}
318+
319+
for _, s := range scopes {
320+
if has, err := bitmap.hasScope(s); has || err != nil {
321+
return has, err
322+
}
323+
}
324+
325+
return false, nil
326+
}
327+
312328
// hasScope returns true if the string has the given scope
313329
func (bitmap accessTokenScopeBitmap) hasScope(scope AccessTokenScope) (bool, error) {
314330
expectedBits, ok := allAccessTokenScopeBits[scope]

models/issues/review.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,13 @@ func (r *Review) LoadAttributes(ctx context.Context) (err error) {
214214
return err
215215
}
216216

217+
// HTMLTypeColorName returns the color used in the ui indicating the review
217218
func (r *Review) HTMLTypeColorName() string {
218219
switch r.Type {
219220
case ReviewTypeApprove:
221+
if !r.Official {
222+
return "grey"
223+
}
220224
if r.Stale {
221225
return "yellow"
222226
}
@@ -231,6 +235,27 @@ func (r *Review) HTMLTypeColorName() string {
231235
return "grey"
232236
}
233237

238+
// TooltipContent returns the locale string describing the review type
239+
func (r *Review) TooltipContent() string {
240+
switch r.Type {
241+
case ReviewTypeApprove:
242+
if r.Stale {
243+
return "repo.issues.review.stale"
244+
}
245+
if !r.Official {
246+
return "repo.issues.review.unofficial"
247+
}
248+
return "repo.issues.review.official"
249+
case ReviewTypeComment:
250+
return "repo.issues.review.comment"
251+
case ReviewTypeReject:
252+
return "repo.issues.review.rejected"
253+
case ReviewTypeRequest:
254+
return "repo.issues.review.requested"
255+
}
256+
return ""
257+
}
258+
234259
// GetReviewByID returns the review by the given ID
235260
func GetReviewByID(ctx context.Context, id int64) (*Review, error) {
236261
review := new(Review)

modules/activitypub/user_settings_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"code.gitea.io/gitea/models/unittest"
1111
user_model "code.gitea.io/gitea/models/user"
1212

13-
_ "code.gitea.io/gitea/models" // https://discourse.gitea.io/t/testfixtures-could-not-clean-table-access-no-such-table-access/4137/4
13+
_ "code.gitea.io/gitea/models" // https://forum.gitea.com/t/testfixtures-could-not-clean-table-access-no-such-table-access/4137/4
1414

1515
"github.com/stretchr/testify/assert"
1616
)

modules/globallock/globallock.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,20 @@ func DefaultLocker() Locker {
2727

2828
// Lock tries to acquire a lock for the given key, it uses the default locker.
2929
// Read the documentation of Locker.Lock for more information about the behavior.
30-
func Lock(ctx context.Context, key string) (context.Context, ReleaseFunc, error) {
30+
func Lock(ctx context.Context, key string) (ReleaseFunc, error) {
3131
return DefaultLocker().Lock(ctx, key)
3232
}
3333

3434
// TryLock tries to acquire a lock for the given key, it uses the default locker.
3535
// Read the documentation of Locker.TryLock for more information about the behavior.
36-
func TryLock(ctx context.Context, key string) (bool, context.Context, ReleaseFunc, error) {
36+
func TryLock(ctx context.Context, key string) (bool, ReleaseFunc, error) {
3737
return DefaultLocker().TryLock(ctx, key)
3838
}
3939

4040
// LockAndDo tries to acquire a lock for the given key and then calls the given function.
4141
// It uses the default locker, and it will return an error if failed to acquire the lock.
4242
func LockAndDo(ctx context.Context, key string, f func(context.Context) error) error {
43-
ctx, release, err := Lock(ctx, key)
43+
release, err := Lock(ctx, key)
4444
if err != nil {
4545
return err
4646
}
@@ -52,7 +52,7 @@ func LockAndDo(ctx context.Context, key string, f func(context.Context) error) e
5252
// TryLockAndDo tries to acquire a lock for the given key and then calls the given function.
5353
// It uses the default locker, and it will return false if failed to acquire the lock.
5454
func TryLockAndDo(ctx context.Context, key string, f func(context.Context) error) (bool, error) {
55-
ok, ctx, release, err := TryLock(ctx, key)
55+
ok, release, err := TryLock(ctx, key)
5656
if err != nil {
5757
return false, err
5858
}

0 commit comments

Comments
 (0)