Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(379)

Side by Side Diff: logdog/appengine/coordinator/hierarchy/project.go

Issue 2575383002: Add server/cache support to gaeconfig. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package hierarchy 5 package hierarchy
6 6
7 import ( 7 import (
8 » "sort" 8 » commonConfig "github.com/luci/luci-go/common/config"
9
10 » "github.com/luci/luci-go/common/config"
11 log "github.com/luci/luci-go/common/logging" 9 log "github.com/luci/luci-go/common/logging"
12 "github.com/luci/luci-go/grpc/grpcutil" 10 "github.com/luci/luci-go/grpc/grpcutil"
13 » "github.com/luci/luci-go/logdog/appengine/coordinator" 11 » "github.com/luci/luci-go/logdog/appengine/coordinator/config"
14 12
15 "golang.org/x/net/context" 13 "golang.org/x/net/context"
16 ) 14 )
17 15
18 func getProjects(c context.Context, r *Request) (*List, error) { 16 func getProjects(c context.Context, r *Request) (*List, error) {
19 // None of the projects are streams. 17 // None of the projects are streams.
20 var l List 18 var l List
21 if r.StreamOnly { 19 if r.StreamOnly {
22 return &l, nil 20 return &l, nil
23 } 21 }
24 22
25 // Get all user-accessible active projects. 23 // Get all user-accessible active projects.
26 » allPcfgs, err := coordinator.ActiveUserProjects(c) 24 » projects, err := config.ActiveUserProjects(c)
27 if err != nil { 25 if err != nil {
28 // If there is an error, we will refrain from filtering projects . 26 // If there is an error, we will refrain from filtering projects .
29 log.WithError(err).Warningf(c, "Failed to get user project list. ") 27 log.WithError(err).Warningf(c, "Failed to get user project list. ")
30 return nil, grpcutil.Internal 28 return nil, grpcutil.Internal
31 } 29 }
32 30
33 » projects := make(projectNameSlice, 0, len(allPcfgs)) 31 » next := commonConfig.ProjectName(r.Next)
34 » for project := range allPcfgs {
35 » » projects = append(projects, project)
36 » }
37 » sort.Sort(projects)
38
39 » next := config.ProjectName(r.Next)
40 skip := r.Skip 32 skip := r.Skip
41 for _, proj := range projects { 33 for _, proj := range projects {
42 // Implement "Next" cursor. If set, don't do anything until we'v e seen it. 34 // Implement "Next" cursor. If set, don't do anything until we'v e seen it.
43 if next != "" { 35 if next != "" {
44 if proj == next { 36 if proj == next {
45 next = "" 37 next = ""
46 } 38 }
47 continue 39 continue
48 } 40 }
49 41
50 // Implement skip. 42 // Implement skip.
51 if skip > 0 { 43 if skip > 0 {
52 skip-- 44 skip--
53 continue 45 continue
54 } 46 }
55 47
56 l.Comp = append(l.Comp, &ListComponent{ 48 l.Comp = append(l.Comp, &ListComponent{
57 Name: string(proj), 49 Name: string(proj),
58 }) 50 })
59 51
60 // Implement limit. 52 // Implement limit.
61 if r.Limit > 0 && len(l.Comp) >= r.Limit { 53 if r.Limit > 0 && len(l.Comp) >= r.Limit {
62 l.Next = string(proj) 54 l.Next = string(proj)
63 break 55 break
64 } 56 }
65 } 57 }
66 58
67 return &l, nil 59 return &l, nil
68 } 60 }
69
70 // projectNameSlice is a sortable slice of config.ProjectName.
71 type projectNameSlice []config.ProjectName
72
73 func (s projectNameSlice) Len() int { return len(s) }
74 func (s projectNameSlice) Less(i, j int) bool { return s[i] < s[j] }
75 func (s projectNameSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698