Skip to content

Commit

Permalink
gogs#3058 gogs#3059 support correct page size and link header
Browse files Browse the repository at this point in the history
  • Loading branch information
unknwon committed Jul 4, 2016
1 parent 528682a commit 4b25bdf
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 32 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra

![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true)

##### Current tip version: 0.9.35 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions)
##### Current tip version: 0.9.36 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions)

| Web | UI | Preview |
|:-------------:|:-------:|:-------:|
Expand Down
4 changes: 4 additions & 0 deletions conf/app.ini
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,10 @@ MIRROR = 300
CLONE = 300
PULL = 300

[api]
; Max number of items will response in a page
MAX_RESPONSE_ITEMS = 50

[i18n]
LANGS = en-US,zh-CN,zh-HK,zh-TW,de-DE,fr-FR,nl-NL,lv-LV,ru-RU,ja-JP,es-ES,pt-BR,pl-PL,bg-BG,it-IT,fi-FI,tr-TR,cs-CZ
NAMES = English,简体中文,繁體中文(香港),繁體中文(台湾),Deutsch,Français,Nederlands,Latviešu,Русский,日本語,Español,Português do Brasil,Polski,български,Italiano,Suomalainen,Türk,čeština
Expand Down
2 changes: 1 addition & 1 deletion gogs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/gogits/gogs/modules/setting"
)

const APP_VER = "0.9.35.0702"
const APP_VER = "0.9.36.0704"

func init() {
runtime.GOMAXPROCS(runtime.NumCPU())
Expand Down
3 changes: 0 additions & 3 deletions models/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -1521,9 +1521,6 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos []*Repository, _ int
}
opts.Keyword = strings.ToLower(opts.Keyword)

if opts.PageSize <= 0 || opts.PageSize > setting.ExplorePagingNum {
opts.PageSize = setting.ExplorePagingNum
}
if opts.Page <= 0 {
opts.Page = 1
}
Expand Down
4 changes: 2 additions & 2 deletions modules/bindata/bindata.go

Large diffs are not rendered by default.

39 changes: 23 additions & 16 deletions modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,20 +159,6 @@ var (
SessionConfig session.Options
CSRFCookieName = "_csrf"

// Git settings
Git struct {
MaxGitDiffLines int
MaxGitDiffLineCharacters int
MaxGitDiffFiles int
GcArgs []string `delim:" "`
Timeout struct {
Migrate int
Mirror int
Clone int
Pull int
} `ini:"git.timeout"`
}

// Cron tasks
Cron struct {
UpdateMirror struct {
Expand All @@ -194,6 +180,25 @@ var (
} `ini:"cron.check_repo_stats"`
}

// Git settings
Git struct {
MaxGitDiffLines int
MaxGitDiffLineCharacters int
MaxGitDiffFiles int
GcArgs []string `delim:" "`
Timeout struct {
Migrate int
Mirror int
Clone int
Pull int
} `ini:"git.timeout"`
}

// API settings
API struct {
MaxResponseItems int
}

// I18n settings
Langs, Names []string
dateLangs map[string]string
Expand Down Expand Up @@ -465,10 +470,12 @@ func NewContext() {

if err = Cfg.Section("markdown").MapTo(&Markdown); err != nil {
log.Fatal(4, "Fail to map Markdown settings: %v", err)
} else if err = Cfg.Section("git").MapTo(&Git); err != nil {
log.Fatal(4, "Fail to map Git settings: %v", err)
} else if err = Cfg.Section("cron").MapTo(&Cron); err != nil {
log.Fatal(4, "Fail to map Cron settings: %v", err)
} else if err = Cfg.Section("git").MapTo(&Git); err != nil {
log.Fatal(4, "Fail to map Git settings: %v", err)
} else if err = Cfg.Section("api").MapTo(&API); err != nil {
log.Fatal(4, "Fail to map API settings: %v", err)
}

Langs = Cfg.Section("i18n").Key("LANGS").Strings(",")
Expand Down
19 changes: 19 additions & 0 deletions routers/api/v1/convert/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2016 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package convert

import (
"github.com/gogits/gogs/modules/setting"
)

// ToCorrectPageSize makes sure page size is in allowed range.
func ToCorrectPageSize(size int) int {
if size <= 0 {
size = 10
} else if size > setting.API.MaxResponseItems {
size = setting.API.MaxResponseItems
}
return size
}
12 changes: 4 additions & 8 deletions routers/api/v1/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ package repo
import (
"path"

"github.com/Unknwon/com"

api "github.com/gogits/go-gogs-client"

"github.com/gogits/gogs/models"
Expand All @@ -23,11 +21,8 @@ import (
func Search(ctx *context.APIContext) {
opts := &models.SearchRepoOptions{
Keyword: path.Base(ctx.Query("q")),
OwnerID: com.StrTo(ctx.Query("uid")).MustInt64(),
PageSize: com.StrTo(ctx.Query("limit")).MustInt(),
}
if opts.PageSize == 0 {
opts.PageSize = 10
OwnerID: ctx.QueryInt64("uid"),
PageSize: convert.ToCorrectPageSize(ctx.QueryInt("limit")),
}

// Check visibility.
Expand All @@ -50,7 +45,7 @@ func Search(ctx *context.APIContext) {
}
}

repos, _, err := models.SearchRepositoryByName(opts)
repos, count, err := models.SearchRepositoryByName(opts)
if err != nil {
ctx.JSON(500, map[string]interface{}{
"ok": false,
Expand All @@ -74,6 +69,7 @@ func Search(ctx *context.APIContext) {
}
}

ctx.SetLinkHeader(int(count), setting.API.MaxResponseItems)
ctx.JSON(200, map[string]interface{}{
"ok": true,
"data": results,
Expand Down
2 changes: 1 addition & 1 deletion templates/.VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.35.0702
0.9.36.0704

0 comments on commit 4b25bdf

Please sign in to comment.