1
0
mirror of https://github.com/golang/go synced 2024-11-24 22:00:09 -07:00

misc/dashboard/codereview: simplify parallel operations for front page, and capture timing info.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/6128044
This commit is contained in:
David Symonds 2012-04-27 23:16:54 +10:00
parent f72c828c67
commit fe252584f5
2 changed files with 38 additions and 30 deletions

View File

@ -8,6 +8,7 @@ import (
"io"
"net/http"
"sync"
"time"
"appengine"
"appengine/datastore"
@ -34,42 +35,42 @@ func handleFront(w http.ResponseWriter, r *http.Request) {
Filter("Closed =", false).
Order("-Modified")
if data.UserIsReviewer {
tableFetch := func(index int, f func(tbl *clTable) error) {
wg.Add(1)
go func() {
defer wg.Done()
tbl := &data.Tables[0]
q := activeCLs.Filter("Reviewer =", currentPerson).Limit(10)
tbl.Title = "CLs assigned to you for review"
tbl.Assignable = true
if _, err := q.GetAll(c, &tbl.CLs); err != nil {
start := time.Now()
if err := f(&data.Tables[index]); err != nil {
errc <- err
}
data.Timing[index] = time.Now().Sub(start)
}()
}
wg.Add(1)
go func() {
defer wg.Done()
tbl := &data.Tables[1]
if data.UserIsReviewer {
tableFetch(0, func(tbl *clTable) error {
q := activeCLs.Filter("Reviewer =", currentPerson).Limit(10)
tbl.Title = "CLs assigned to you for review"
tbl.Assignable = true
_, err := q.GetAll(c, &tbl.CLs)
return err
})
}
tableFetch(1, func(tbl *clTable) error {
q := activeCLs.Filter("Author =", currentPerson).Limit(10)
tbl.Title = "CLs sent by you"
tbl.Assignable = true
if _, err := q.GetAll(c, &tbl.CLs); err != nil {
errc <- err
}
}()
_, err := q.GetAll(c, &tbl.CLs)
return err
})
wg.Add(1)
go func() {
defer wg.Done()
tbl := &data.Tables[2]
tableFetch(2, func(tbl *clTable) error {
q := activeCLs.Limit(50)
tbl.Title = "Other active CLs"
tbl.Assignable = true
if _, err := q.GetAll(c, &tbl.CLs); err != nil {
errc <- err
return
return err
}
// filter
if data.UserIsReviewer {
@ -81,22 +82,19 @@ func handleFront(w http.ResponseWriter, r *http.Request) {
}
}
}
}()
return nil
})
wg.Add(1)
go func() {
defer wg.Done()
tbl := &data.Tables[3]
tableFetch(3, func(tbl *clTable) error {
q := datastore.NewQuery("CL").
Filter("Closed =", true).
Order("-Modified").
Limit(10)
tbl.Title = "Recently closed CLs"
tbl.Assignable = false
if _, err := q.GetAll(c, &tbl.CLs); err != nil {
errc <- err
}
}()
_, err := q.GetAll(c, &tbl.CLs)
return err
})
wg.Wait()
@ -119,6 +117,7 @@ func handleFront(w http.ResponseWriter, r *http.Request) {
type frontPageData struct {
Tables [4]clTable
Timing [4]time.Duration
Reviewers []string
UserIsReviewer bool
@ -175,6 +174,10 @@ var frontPage = template.Must(template.New("front").Funcs(template.FuncMap{
color: blue;
text-decoration: none; /* no link underline */
}
address {
font-size: 10px;
text-align: right;
}
.email {
font-family: monospace;
}
@ -235,6 +238,11 @@ var frontPage = template.Must(template.New("front").Funcs(template.FuncMap{
{{end}}
{{end}}
<hr />
<address>
datastore timing: {{range .Timing}} {{.}}{{end}}
</address>
</body>
</html>
`))

View File

@ -4,10 +4,10 @@ package dashboard
import (
"net/http"
"time"
"appengine"
"appengine/datastore"
"time"
)
func init() {