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

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

Issue 1269113005: A transparent cache for datastore, backed by memcache. (Closed) Base URL: https://github.com/luci/gae.git@add_meta
Patch Set: add test for per-model expiration Created 5 years, 4 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 "errors" 9 "errors"
10 "fmt" 10 "fmt"
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 val = blobstore.Key(s) 285 val = blobstore.Key(s)
286 default: 286 default:
287 err = fmt.Errorf("read: unknown type! %v", typb) 287 err = fmt.Errorf("read: unknown type! %v", typb)
288 } 288 }
289 if err == nil { 289 if err == nil {
290 err = p.SetValue(val, is) 290 err = p.SetValue(val, is)
291 } 291 }
292 return 292 return
293 } 293 }
294 294
295 // Write writes an entire PropertyMap to the buffer. `context` 295 // Write writes an entire PropertyMap to the buffer. `context` behaves the same
296 // behaves the same way that it does for WriteKey. If 296 // way that it does for WriteKey. If WritePropertyMapDeterministic is true, then
297 // WritePropertyMapDeterministic is true, then the rows will be sorted by 297 // the rows will be sorted by property name before they're serialized to buf
298 // property name before they're serialized to buf (mostly useful for testing, 298 // (mostly useful for testing, but also potentially useful if you need to make
299 // but also potentially useful if you need to make a hash of the property data). 299 // a hash of the property data).
300 //
301 // Write skips metadata keys.
300 func (pm PropertyMap) Write(buf Buffer, context KeyContext) (err error) { 302 func (pm PropertyMap) Write(buf Buffer, context KeyContext) (err error) {
301 defer recoverTo(&err) 303 defer recoverTo(&err)
302 rows := make(sort.StringSlice, 0, len(pm)) 304 rows := make(sort.StringSlice, 0, len(pm))
303 tmpBuf := &bytes.Buffer{} 305 tmpBuf := &bytes.Buffer{}
304 for name, vals := range pm { 306 for name, vals := range pm {
307 if isMetaKey(name) {
308 continue
309 }
305 tmpBuf.Reset() 310 tmpBuf.Reset()
306 _, e := cmpbin.WriteString(tmpBuf, name) 311 _, e := cmpbin.WriteString(tmpBuf, name)
307 panicIf(e) 312 panicIf(e)
308 _, e = cmpbin.WriteUint(tmpBuf, uint64(len(vals))) 313 _, e = cmpbin.WriteUint(tmpBuf, uint64(len(vals)))
309 panicIf(e) 314 panicIf(e)
310 for _, p := range vals { 315 for _, p := range vals {
311 panicIf(p.Write(tmpBuf, context)) 316 panicIf(p.Write(tmpBuf, context))
312 } 317 }
313 rows = append(rows, tmpBuf.String()) 318 rows = append(rows, tmpBuf.String())
314 } 319 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 } 373 }
369 } 374 }
370 375
371 func recoverTo(err *error) { 376 func recoverTo(err *error) {
372 if r := recover(); r != nil { 377 if r := recover(); r != nil {
373 if rerr := r.(parseError); rerr != nil { 378 if rerr := r.(parseError); rerr != nil {
374 *err = error(rerr) 379 *err = error(rerr)
375 } 380 }
376 } 381 }
377 } 382 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698