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

Side by Side Diff: service/datastore/index.go

Issue 1364333002: Add AutoIndex (Closed) Base URL: https://github.com/luci/gae.git@add_full_consistency
Patch Set: Created 5 years, 2 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package datastore 5 package datastore
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "fmt" 9 "fmt"
10 "strings" 10 "strings"
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 return false 221 return false
222 } 222 }
223 for _, sb := range id.SortBy { 223 for _, sb := range id.SortBy {
224 if sb.Property == "" || sb.Property == "__ancestor__" { 224 if sb.Property == "" || sb.Property == "__ancestor__" {
225 return false 225 return false
226 } 226 }
227 } 227 }
228 return true 228 return true
229 } 229 }
230 230
231 // YAMLString returns the YAML representation of this IndexDefinition.
232 //
233 // If the index definition is Builtin() or not Compound(), this will return
234 // an error.
235 func (id *IndexDefinition) YAMLString() (string, error) {
236 if id.Builtin() || !id.Compound() {
237 return "", fmt.Errorf("cannot generate YAML for this IndexDefini tion")
238 }
239
240 ret := &bytes.Buffer{}
Vadim Sh. 2015/09/24 19:17:29 nit: just bytes.Buffer{}, no need for dynamic allo
iannucci 2015/09/24 19:52:34 Common misconception: there's no actual difference
Vadim Sh. 2015/09/24 19:57:50 """In the current compilers, if a variable has its
iannucci 2015/09/24 20:12:59 it made more sense before I had the ws function. t
241 indent := 0
242
243 first := true
244 ws := func(s string) {
245 nl := "\n"
246 if first {
247 nl = ""
248 first = false
249 }
250 _, err := fmt.Fprintf(ret, "%s%s%s", nl, strings.Repeat(" ", in dent), s)
251 if err != nil {
Vadim Sh. 2015/09/24 19:17:29 just remove errcheck from pre-commit-go.yml >_< Ch
iannucci 2015/09/24 19:52:34 lol ok
252 panic(err)
253 }
254 }
255
256 ws(fmt.Sprintf("- kind: %s", id.Kind))
257 indent++
258 if id.Ancestor {
259 ws("ancestor: yes")
260 }
261 ws("properties:")
262 for _, o := range id.SortBy {
263 ws(fmt.Sprintf("- name: %s", o.Property))
264 if o.Descending {
265 indent++
Vadim Sh. 2015/09/24 19:17:29 :) just pass indent explicitly, e.g. ws("properti
iannucci 2015/09/24 19:52:35 done :)
266 ws("direction: desc")
267 indent--
268 }
269 }
270 return ret.String(), nil
271 }
272
231 func (id *IndexDefinition) String() string { 273 func (id *IndexDefinition) String() string {
232 ret := &bytes.Buffer{} 274 ret := &bytes.Buffer{}
233 wr := func(r rune) { 275 wr := func(r rune) {
234 _, err := ret.WriteRune(r) 276 _, err := ret.WriteRune(r)
235 if err != nil { 277 if err != nil {
236 panic(err) 278 panic(err)
237 } 279 }
238 } 280 }
239 281
240 ws := func(s string) { 282 ws := func(s string) {
(...skipping 15 matching lines...) Expand all
256 } 298 }
257 for _, sb := range id.SortBy { 299 for _, sb := range id.SortBy {
258 wr('/') 300 wr('/')
259 if sb.Descending { 301 if sb.Descending {
260 wr('-') 302 wr('-')
261 } 303 }
262 ws(sb.Property) 304 ws(sb.Property)
263 } 305 }
264 return ret.String() 306 return ret.String()
265 } 307 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698