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

Side by Side Diff: luci_config/server/cfgclient/config.go

Issue 2642343003: luci_config: Request content only when desired. (Closed)
Patch Set: Created 3 years, 11 months 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
« no previous file with comments | « no previous file | luci_config/server/cfgclient/config_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The LUCI Authors. All rights reserved. 1 // Copyright 2016 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 cfgclient 5 package cfgclient
6 6
7 import ( 7 import (
8 "net/url" 8 "net/url"
9 9
10 "github.com/luci/luci-go/common/config" 10 "github.com/luci/luci-go/common/config"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 // 56 //
57 // Corresponds to auth.AsUser. 57 // Corresponds to auth.AsUser.
58 AsUser = Authority(backend.AsUser) 58 AsUser = Authority(backend.AsUser)
59 ) 59 )
60 60
61 // ServiceURL returns the URL of the config service. 61 // ServiceURL returns the URL of the config service.
62 func ServiceURL(c context.Context) url.URL { return backend.Get(c).ServiceURL(c) } 62 func ServiceURL(c context.Context) url.URL { return backend.Get(c).ServiceURL(c) }
63 63
64 // Get retrieves a single configuration file. 64 // Get retrieves a single configuration file.
65 // 65 //
66 // r, if supplied, is a MultiResolver that will load the configuration data. 66 // r, if not nil, is a Resolver that will load the configuration data. If nil,
67 // If nil, the configuration data will be discarded (useful if you only care 67 // the configuration data will be discarded (useful if you only care about
68 // about metas). 68 // metas).
69 // 69 //
70 // meta, if not nil, will have the configuration's Meta loaded into it on 70 // meta, if not nil, will have the configuration's Meta loaded into it on
71 // success. 71 // success.
72 func Get(c context.Context, a Authority, cs cfgtypes.ConfigSet, path string, r R esolver, meta *Meta) error { 72 func Get(c context.Context, a Authority, cs cfgtypes.ConfigSet, path string, r R esolver, meta *Meta) error {
73 be := backend.Get(c) 73 be := backend.Get(c)
74 74
75 params := backend.Params{ 75 params := backend.Params{
76 Authority: backend.Authority(a), 76 Authority: backend.Authority(a),
77 » » Content: true, 77 » » Content: r != nil,
78 } 78 }
79 79
80 if fr, ok := r.(FormattingResolver); ok { 80 if fr, ok := r.(FormattingResolver); ok {
81 params.FormatSpec = fr.Format() 81 params.FormatSpec = fr.Format()
82 } 82 }
83 83
84 item, err := be.Get(c, string(cs), path, params) 84 item, err := be.Get(c, string(cs), path, params)
85 if err != nil { 85 if err != nil {
86 return err 86 return err
87 } 87 }
88 88
89 if meta != nil { 89 if meta != nil {
90 *meta = *makeMeta(&item.Meta) 90 *meta = *makeMeta(&item.Meta)
91 } 91 }
92 if r == nil { 92 if r == nil {
93 return nil 93 return nil
94 } 94 }
95 return r.Resolve(item) 95 return r.Resolve(item)
96 } 96 }
97 97
98 // Projects retrieves all named project configurations. 98 // Projects retrieves all named project configurations.
99 // 99 //
100 // r, if supplied, is a MultiResolver that will load the configuration data. 100 // r, if not nil, is a MultiResolver that will load the configuration data.
101 // If nil, the configuration data will be discarded (useful if you only care 101 // If nil, the configuration data will be discarded (useful if you only care
102 // about metas). If the MultiResolver operates on a slice (which it probably 102 // about metas). If the MultiResolver operates on a slice (which it probably
103 // will), each meta and/or error index will correspond to its slice index. 103 // will), each meta and/or error index will correspond to its slice index.
104 // 104 //
105 // If meta is not nil, it will be populated with a slice of *Meta entries 105 // If meta is not nil, it will be populated with a slice of *Meta entries
106 // for each loaded configuration, in the same order that r receives them. If 106 // for each loaded configuration, in the same order that r receives them. If
107 // r resolves to a slice, the indexes for each resolved slice entry and meta 107 // r resolves to a slice, the indexes for each resolved slice entry and meta
108 // entry should align unless r is doing something funky. 108 // entry should align unless r is doing something funky.
109 // 109 //
110 // Two types of failure may happen here. A systemic failure fails to load the 110 // Two types of failure may happen here. A systemic failure fails to load the
(...skipping 14 matching lines...) Expand all
125 return getAll(c, a, backend.GetAllRef, path, r, meta) 125 return getAll(c, a, backend.GetAllRef, path, r, meta)
126 } 126 }
127 127
128 func getAll(c context.Context, a Authority, t backend.GetAllTarget, path string, r MultiResolver, 128 func getAll(c context.Context, a Authority, t backend.GetAllTarget, path string, r MultiResolver,
129 meta *[]*Meta) error { 129 meta *[]*Meta) error {
130 130
131 be := backend.Get(c) 131 be := backend.Get(c)
132 132
133 params := backend.Params{ 133 params := backend.Params{
134 Authority: backend.Authority(a), 134 Authority: backend.Authority(a),
135 » » Content: true, 135 » » Content: r != nil,
136 } 136 }
137 137
138 // If we're fetching content, apply a formatting specification.
138 if fr, ok := r.(FormattingResolver); ok { 139 if fr, ok := r.(FormattingResolver); ok {
139 params.FormatSpec = fr.Format() 140 params.FormatSpec = fr.Format()
140 } 141 }
141 142
142 items, err := be.GetAll(c, t, path, params) 143 items, err := be.GetAll(c, t, path, params)
143 if err != nil { 144 if err != nil {
144 return err 145 return err
145 } 146 }
146 147
147 // Load our metas. 148 // Load our metas.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 } 187 }
187 188
188 func makeMeta(b *backend.Meta) *Meta { 189 func makeMeta(b *backend.Meta) *Meta {
189 return &Meta{ 190 return &Meta{
190 ConfigSet: cfgtypes.ConfigSet(b.ConfigSet), 191 ConfigSet: cfgtypes.ConfigSet(b.ConfigSet),
191 Path: b.Path, 192 Path: b.Path,
192 ContentHash: b.ContentHash, 193 ContentHash: b.ContentHash,
193 Revision: b.Revision, 194 Revision: b.Revision,
194 } 195 }
195 } 196 }
OLDNEW
« no previous file with comments | « no previous file | luci_config/server/cfgclient/config_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698