Skip to content

Commit 9bb91fc

Browse files
authored
Merge branch 'master' into jt/release-tag-compare
2 parents d1f1d16 + 8c8471e commit 9bb91fc

File tree

14 files changed

+136
-55
lines changed

14 files changed

+136
-55
lines changed

models/session.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,6 @@ func CountSessions() (int64, error) {
117117

118118
// CleanupSessions cleans up expired sessions
119119
func CleanupSessions(maxLifetime int64) error {
120-
_, err := x.Where("created_unix <= ?", timeutil.TimeStampNow().Add(-maxLifetime)).Delete(&Session{})
120+
_, err := x.Where("expiry <= ?", timeutil.TimeStampNow().Add(-maxLifetime)).Delete(&Session{})
121121
return err
122122
}

modules/git/commit_info_nogogit.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,13 @@ func (tes Entries) GetCommitsInfo(commit *Commit, treePath string, cache *LastCo
102102
}
103103

104104
func getLastCommitForPathsByCache(commitID, treePath string, paths []string, cache *LastCommitCache) (map[string]*Commit, []string, error) {
105+
wr, rd, cancel := CatFileBatch(cache.repo.Path)
106+
defer cancel()
107+
105108
var unHitEntryPaths []string
106109
var results = make(map[string]*Commit)
107110
for _, p := range paths {
108-
lastCommit, err := cache.Get(commitID, path.Join(treePath, p))
111+
lastCommit, err := cache.Get(commitID, path.Join(treePath, p), wr, rd)
109112
if err != nil {
110113
return nil, nil, err
111114
}

modules/git/last_commit_cache_nogogit.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
package git
88

99
import (
10+
"bufio"
11+
"io"
1012
"path"
1113
)
1214

@@ -34,7 +36,7 @@ func NewLastCommitCache(repoPath string, gitRepo *Repository, ttl func() int64,
3436
}
3537

3638
// Get get the last commit information by commit id and entry path
37-
func (c *LastCommitCache) Get(ref, entryPath string) (interface{}, error) {
39+
func (c *LastCommitCache) Get(ref, entryPath string, wr *io.PipeWriter, rd *bufio.Reader) (interface{}, error) {
3840
v := c.cache.Get(c.getCacheKey(c.repoPath, ref, entryPath))
3941
if vs, ok := v.(string); ok {
4042
log("LastCommitCache hit level 1: [%s:%s:%s]", ref, entryPath, vs)
@@ -46,7 +48,10 @@ func (c *LastCommitCache) Get(ref, entryPath string) (interface{}, error) {
4648
if err != nil {
4749
return nil, err
4850
}
49-
commit, err := c.repo.getCommit(id)
51+
if _, err := wr.Write([]byte(vs + "\n")); err != nil {
52+
return nil, err
53+
}
54+
commit, err := c.repo.getCommitFromBatchReader(rd, id)
5055
if err != nil {
5156
return nil, err
5257
}

modules/git/repo_commit_nogogit.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ package git
99
import (
1010
"bufio"
1111
"errors"
12-
"fmt"
1312
"io"
1413
"io/ioutil"
14+
"os"
15+
"path/filepath"
1516
"strings"
1617
)
1718

@@ -34,6 +35,18 @@ func (repo *Repository) ResolveReference(name string) (string, error) {
3435

3536
// GetRefCommitID returns the last commit ID string of given reference (branch or tag).
3637
func (repo *Repository) GetRefCommitID(name string) (string, error) {
38+
if strings.HasPrefix(name, "refs/") {
39+
// We're gonna try just reading the ref file as this is likely to be quicker than other options
40+
fileInfo, err := os.Lstat(filepath.Join(repo.Path, name))
41+
if err == nil && fileInfo.Mode().IsRegular() && fileInfo.Size() == 41 {
42+
ref, err := ioutil.ReadFile(filepath.Join(repo.Path, name))
43+
44+
if err == nil && SHAPattern.Match(ref[:40]) && ref[40] == '\n' {
45+
return string(ref[:40]), nil
46+
}
47+
}
48+
}
49+
3750
stdout, err := NewCommand("show-ref", "--verify", "--hash", name).RunInDir(repo.Path)
3851
if err != nil {
3952
if strings.Contains(err.Error(), "not a valid ref") {
@@ -69,6 +82,11 @@ func (repo *Repository) getCommit(id SHA1) (*Commit, error) {
6982
}()
7083

7184
bufReader := bufio.NewReader(stdoutReader)
85+
86+
return repo.getCommitFromBatchReader(bufReader, id)
87+
}
88+
89+
func (repo *Repository) getCommitFromBatchReader(bufReader *bufio.Reader, id SHA1) (*Commit, error) {
7290
_, typ, size, err := ReadBatchLine(bufReader)
7391
if err != nil {
7492
if errors.Is(err, io.EOF) {
@@ -106,7 +124,6 @@ func (repo *Repository) getCommit(id SHA1) (*Commit, error) {
106124
case "commit":
107125
return CommitFromReader(repo, id, io.LimitReader(bufReader, size))
108126
default:
109-
_ = stdoutReader.CloseWithError(fmt.Errorf("unknown typ: %s", typ))
110127
log("Unknown typ: %s", typ)
111128
return nil, ErrNotExist{
112129
ID: id.String(),

modules/queue/queue_disk_channel.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ func NewPersistableChannelQueue(handle HandlerFunc, cfg, exemplar interface{}) (
7575
BatchLength: config.BatchLength,
7676
BlockTimeout: 1 * time.Second,
7777
BoostTimeout: 5 * time.Minute,
78-
BoostWorkers: 5,
79-
MaxWorkers: 6,
78+
BoostWorkers: 1,
79+
MaxWorkers: 5,
8080
},
81-
Workers: 1,
81+
Workers: 0,
8282
Name: config.Name + "-level",
8383
},
8484
DataDir: config.DataDir,

modules/queue/unique_queue_disk_channel.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ func NewPersistableChannelUniqueQueue(handle HandlerFunc, cfg, exemplar interfac
7373
WorkerPoolConfiguration: WorkerPoolConfiguration{
7474
QueueLength: config.QueueLength,
7575
BatchLength: config.BatchLength,
76-
BlockTimeout: 0,
77-
BoostTimeout: 0,
78-
BoostWorkers: 0,
79-
MaxWorkers: 1,
76+
BlockTimeout: 1 * time.Second,
77+
BoostTimeout: 5 * time.Minute,
78+
BoostWorkers: 1,
79+
MaxWorkers: 5,
8080
},
81-
Workers: 1,
81+
Workers: 0,
8282
Name: config.Name + "-level",
8383
},
8484
DataDir: config.DataDir,

modules/queue/workerpool.go

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,52 @@ func (p *WorkerPool) Push(data Data) {
7070
atomic.AddInt64(&p.numInQueue, 1)
7171
p.lock.Lock()
7272
if p.blockTimeout > 0 && p.boostTimeout > 0 && (p.numberOfWorkers <= p.maxNumberOfWorkers || p.maxNumberOfWorkers < 0) {
73-
p.lock.Unlock()
73+
if p.numberOfWorkers == 0 {
74+
p.zeroBoost()
75+
} else {
76+
p.lock.Unlock()
77+
}
7478
p.pushBoost(data)
7579
} else {
7680
p.lock.Unlock()
7781
p.dataChan <- data
7882
}
7983
}
8084

85+
func (p *WorkerPool) zeroBoost() {
86+
ctx, cancel := context.WithCancel(p.baseCtx)
87+
mq := GetManager().GetManagedQueue(p.qid)
88+
boost := p.boostWorkers
89+
if (boost+p.numberOfWorkers) > p.maxNumberOfWorkers && p.maxNumberOfWorkers >= 0 {
90+
boost = p.maxNumberOfWorkers - p.numberOfWorkers
91+
}
92+
if mq != nil {
93+
log.Warn("WorkerPool: %d (for %s) has zero workers - adding %d temporary workers for %s", p.qid, mq.Name, boost, p.boostTimeout)
94+
95+
start := time.Now()
96+
pid := mq.RegisterWorkers(boost, start, true, start.Add(p.boostTimeout), cancel, false)
97+
go func() {
98+
select {
99+
case <-ctx.Done():
100+
case <-time.After(p.boostTimeout):
101+
}
102+
mq.RemoveWorkers(pid)
103+
cancel()
104+
}()
105+
} else {
106+
log.Warn("WorkerPool: %d has zero workers - adding %d temporary workers for %s", p.qid, p.boostWorkers, p.boostTimeout)
107+
go func() {
108+
select {
109+
case <-ctx.Done():
110+
case <-time.After(p.boostTimeout):
111+
}
112+
cancel()
113+
}()
114+
}
115+
p.lock.Unlock()
116+
p.addWorkers(ctx, boost)
117+
}
118+
81119
func (p *WorkerPool) pushBoost(data Data) {
82120
select {
83121
case p.dataChan <- data:
@@ -112,7 +150,7 @@ func (p *WorkerPool) pushBoost(data Data) {
112150
log.Warn("WorkerPool: %d (for %s) Channel blocked for %v - adding %d temporary workers for %s, block timeout now %v", p.qid, mq.Name, ourTimeout, boost, p.boostTimeout, p.blockTimeout)
113151

114152
start := time.Now()
115-
pid := mq.RegisterWorkers(boost, start, false, start, cancel, false)
153+
pid := mq.RegisterWorkers(boost, start, true, start.Add(p.boostTimeout), cancel, false)
116154
go func() {
117155
<-ctx.Done()
118156
mq.RemoveWorkers(pid)

modules/structs/admin_user.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ type EditUserOption struct {
3232
FullName *string `json:"full_name" binding:"MaxSize(100)"`
3333
Password string `json:"password" binding:"MaxSize(255)"`
3434
MustChangePassword *bool `json:"must_change_password"`
35-
Website *string `json:"website" binding:"MaxSize(50)"`
35+
Website *string `json:"website" binding:"OmitEmpty;ValidUrl;MaxSize(255)"`
3636
Location *string `json:"location" binding:"MaxSize(50)"`
37+
Description *string `json:"description" binding:"MaxSize(255)"`
3738
Active *bool `json:"active"`
3839
Admin *bool `json:"admin"`
3940
AllowGitHook *bool `json:"allow_git_hook"`

modules/structs/org.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ type CreateOrgOption struct {
2222
// required: true
2323
UserName string `json:"username" binding:"Required"`
2424
FullName string `json:"full_name"`
25-
Description string `json:"description"`
26-
Website string `json:"website"`
27-
Location string `json:"location"`
25+
Description string `json:"description" binding:"MaxSize(255)"`
26+
Website string `json:"website" binding:"ValidUrl;MaxSize(255)"`
27+
Location string `json:"location" binding:"MaxSize(50)"`
2828
// possible values are `public` (default), `limited` or `private`
2929
// enum: public,limited,private
3030
Visibility string `json:"visibility" binding:"In(,public,limited,private)"`
@@ -34,9 +34,9 @@ type CreateOrgOption struct {
3434
// EditOrgOption options for editing an organization
3535
type EditOrgOption struct {
3636
FullName string `json:"full_name"`
37-
Description string `json:"description"`
38-
Website string `json:"website"`
39-
Location string `json:"location"`
37+
Description string `json:"description" binding:"MaxSize(255)"`
38+
Website string `json:"website" binding:"ValidUrl;MaxSize(255)"`
39+
Location string `json:"location" binding:"MaxSize(50)"`
4040
// possible values are `public`, `limited` or `private`
4141
// enum: public,limited,private
4242
Visibility string `json:"visibility" binding:"In(,public,limited,private)"`

modules/structs/user.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ type User struct {
3737
Location string `json:"location"`
3838
// the user's website
3939
Website string `json:"website"`
40-
// the user's biography
41-
Description string `json:"bio"`
40+
// the user's description
41+
Description string `json:"description"`
4242
}
4343

4444
// MarshalJSON implements the json.Marshaler interface for User, adding field(s) for backward compatibility

routers/api/v1/admin/user.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ func EditUser(ctx *context.APIContext) {
203203
if form.Location != nil {
204204
u.Location = *form.Location
205205
}
206+
if form.Description != nil {
207+
u.Description = *form.Description
208+
}
206209
if form.Active != nil {
207210
u.IsActive = *form.Active
208211
}

templates/swagger/v1_json.tmpl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13800,6 +13800,10 @@
1380013800
"type": "boolean",
1380113801
"x-go-name": "AllowImportLocal"
1380213802
},
13803+
"description": {
13804+
"type": "string",
13805+
"x-go-name": "Description"
13806+
},
1380313807
"email": {
1380413808
"type": "string",
1380513809
"format": "email",
@@ -16251,16 +16255,16 @@
1625116255
"type": "string",
1625216256
"x-go-name": "AvatarURL"
1625316257
},
16254-
"bio": {
16255-
"description": "the user's biography",
16256-
"type": "string",
16257-
"x-go-name": "Description"
16258-
},
1625916258
"created": {
1626016259
"type": "string",
1626116260
"format": "date-time",
1626216261
"x-go-name": "Created"
1626316262
},
16263+
"description": {
16264+
"description": "the user's description",
16265+
"type": "string",
16266+
"x-go-name": "Description"
16267+
},
1626416268
"email": {
1626516269
"type": "string",
1626616270
"format": "email",

0 commit comments

Comments
 (0)