PLT-6896 per-paging for logs (#7903)
* PLT-6896 Read logs from last * Getting rid of file.Stats * remove deprecated value * Make non-reassigned value constant
Этот коммит содержится в:
коммит произвёл
Chris
родитель
c39788b64b
Коммит
ddd99f7476
@@ -11,9 +11,11 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
PAGE_DEFAULT = 0
|
||||
PER_PAGE_DEFAULT = 60
|
||||
PER_PAGE_MAXIMUM = 200
|
||||
PAGE_DEFAULT = 0
|
||||
PER_PAGE_DEFAULT = 60
|
||||
PER_PAGE_MAXIMUM = 200
|
||||
LOGS_PER_PAGE_DEFAULT = 10000
|
||||
LOGS_PER_PAGE_MAXIMUM = 10000
|
||||
)
|
||||
|
||||
type ApiParams struct {
|
||||
@@ -43,6 +45,7 @@ type ApiParams struct {
|
||||
ActionId string
|
||||
Page int
|
||||
PerPage int
|
||||
LogsPerPage int
|
||||
Permanent bool
|
||||
}
|
||||
|
||||
@@ -165,5 +168,13 @@ func ApiParamsFromRequest(r *http.Request) *ApiParams {
|
||||
params.PerPage = val
|
||||
}
|
||||
|
||||
if val, err := strconv.Atoi(r.URL.Query().Get("logs_per_page")); err != nil || val < 0 {
|
||||
params.LogsPerPage = LOGS_PER_PAGE_DEFAULT
|
||||
} else if val > LOGS_PER_PAGE_MAXIMUM {
|
||||
params.LogsPerPage = LOGS_PER_PAGE_MAXIMUM
|
||||
} else {
|
||||
params.LogsPerPage = val
|
||||
}
|
||||
|
||||
return params
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ func getLogs(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
lines, err := c.App.GetLogs(c.Params.Page, c.Params.PerPage)
|
||||
lines, err := c.App.GetLogs(c.Params.Page, c.Params.LogsPerPage)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
||||
@@ -308,18 +308,18 @@ func TestGetLogs(t *testing.T) {
|
||||
logs, resp := th.SystemAdminClient.GetLogs(0, 10)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
// if len(logs) != 10 {
|
||||
// t.Log(len(logs))
|
||||
// t.Fatal("wrong length")
|
||||
// }
|
||||
if len(logs) != 10 {
|
||||
t.Log(len(logs))
|
||||
t.Fatal("wrong length")
|
||||
}
|
||||
|
||||
logs, resp = th.SystemAdminClient.GetLogs(1, 10)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
// if len(logs) != 10 {
|
||||
// t.Log(len(logs))
|
||||
// t.Fatal("wrong length")
|
||||
// }
|
||||
if len(logs) != 10 {
|
||||
t.Log(len(logs))
|
||||
t.Fatal("wrong length")
|
||||
}
|
||||
|
||||
logs, resp = th.SystemAdminClient.GetLogs(-1, -1)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
Ссылка в новой задаче
Block a user