index: move more key building into keyType

Change-Id: I2928f4ba345ebe11a3d6c9f63a1a381cb13bfb28
This commit is contained in:
Brad Fitzpatrick 2011-11-29 18:14:34 -08:00
parent f8fa2b2584
commit 352db24f46
2 changed files with 31 additions and 9 deletions

View File

@ -27,18 +27,41 @@ type keyType struct {
}
func (k *keyType) Prefix(args ...interface{}) string {
return k.build(true, args...)
}
func (k *keyType) Key(args ...interface{}) string {
return k.build(false, args...)
}
func (k *keyType) build(finalPipe bool, args ...interface{}) string {
var buf bytes.Buffer
buf.WriteString(k.name)
for _, arg := range args {
for i, arg := range args {
buf.WriteString("|")
// TODO(bradfitz): verify the type matches
if s, ok := arg.(string); ok {
buf.WriteString(s)
} else {
buf.WriteString(arg.(fmt.Stringer).String())
switch k.parts[i].typ {
case typeReverseTime:
s, ok := arg.(string)
if !ok {
s = arg.(fmt.Stringer).String()
}
const example = "2011-01-23T05:23:12"
if len(s) < len(example) || s[4] != '-' && s[10] != 'T' {
panic("doesn't look like a time: " + s)
}
buf.WriteString(reverseTimeString(s))
default:
// TODO(bradfitz): reverse time and such
if s, ok := arg.(string); ok {
buf.WriteString(s)
} else {
buf.WriteString(arg.(fmt.Stringer).String())
}
}
}
buf.WriteString("|")
if finalPipe {
buf.WriteString("|")
}
return buf.String()
}

View File

@ -121,8 +121,7 @@ func (ix *Index) populateClaim(br *blobref.BlobRef, ss *schema.Superset, sniffer
bm.Set("signerkeyid:"+vr.CamliSigner.String(), verifiedKeyId)
// TODO(bradfitz): use keyRecentPermanode here instead of pipes() with "recpn".
recentKey := pipes("recpn", verifiedKeyId, reverseTimeString(ss.ClaimDate), br)
recentKey := keyRecentPermanode.Key(verifiedKeyId, ss.ClaimDate, br)
bm.Set(recentKey, pnbr.String())
claimKey := pipes("claim", pnbr, verifiedKeyId, ss.ClaimDate, br)