From 3e9fc4c28ab7d11f6cad05a9c005af91509b98d3 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sun, 27 Nov 2011 21:50:50 -0500 Subject: [PATCH] Move special-casing of certain properties out of mysqlindexer and up to a common spot. Change-Id: I543ce701e081d2b261b03b6721d5aa053bd231af --- lib/go/camli/mysqlindexer/receive.go | 24 ++++++++++-------------- lib/go/camli/search/search.go | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/lib/go/camli/mysqlindexer/receive.go b/lib/go/camli/mysqlindexer/receive.go index eb2a83206..63207591f 100644 --- a/lib/go/camli/mysqlindexer/receive.go +++ b/lib/go/camli/mysqlindexer/receive.go @@ -29,6 +29,7 @@ import ( "camli/jsonsign" "camli/magic" "camli/schema" + "camli/search" ) func (mi *Indexer) ReceiveBlob(blobRef *blobref.BlobRef, source io.Reader) (retsb blobref.SizedBlobRef, err os.Error) { @@ -110,26 +111,21 @@ func (mi *Indexer) populateClaim(blobRef *blobref.BlobRef, camli *schema.Superse } if verifiedKeyId != "" { - switch camli.Attribute { - case "camliRoot", "tag", "title": - // TODO(bradfitz,mpl): these tag names are hard-coded. - // we should probably have a config file of attributes - // and properties (e.g. which way(s) they're indexed) + if search.IsIndexedAttribute(camli.Attribute) { if err = mi.db.Execute("INSERT IGNORE INTO signerattrvalue (keyid, attr, value, claimdate, blobref, permanode) "+ "VALUES (?, ?, ?, ?, ?, ?)", verifiedKeyId, camli.Attribute, camli.Value, camli.ClaimDate, blobRef.String(), camli.Permanode); err != nil { return } - if camli.Attribute == "tag" || camli.Attribute == "title" { - // Identical copy for fulltext searches - // TODO(mpl): do the DELETEs as well - if err = mi.db.Execute("INSERT IGNORE INTO signerattrvalueft (keyid, attr, value, claimdate, blobref, permanode) "+ - "VALUES (?, ?, ?, ?, ?, ?)", - verifiedKeyId, camli.Attribute, camli.Value, - camli.ClaimDate, blobRef.String(), camli.Permanode); err != nil { - return - } + } + if search.IsFulltextAttribute(camli.Attribute) { + // TODO(mpl): do the DELETEs as well + if err = mi.db.Execute("INSERT IGNORE INTO signerattrvalueft (keyid, attr, value, claimdate, blobref, permanode) "+ + "VALUES (?, ?, ?, ?, ?, ?)", + verifiedKeyId, camli.Attribute, camli.Value, + camli.ClaimDate, blobRef.String(), camli.Permanode); err != nil { + return } } if strings.HasPrefix(camli.Attribute, "camliPath:") { diff --git a/lib/go/camli/search/search.go b/lib/go/camli/search/search.go index 3c93388cd..abf190a05 100644 --- a/lib/go/camli/search/search.go +++ b/lib/go/camli/search/search.go @@ -120,6 +120,7 @@ type Index interface { // and specific 'value', find the most recent permanode that has // a corresponding 'set-attribute' claim attached. // Returns os.ENOENT if none is found. + // Only attributes white-listed by IsIndexedAttribute are valid. PermanodeOfSignerAttrValue(signer *blobref.BlobRef, attr, val string) (*blobref.BlobRef, os.Error) PathsOfSignerTarget(signer, target *blobref.BlobRef) ([]*Path, os.Error) @@ -131,3 +132,20 @@ type Index interface { // provided time 'at', or most recent if 'at' is nil. PathLookup(signer, base *blobref.BlobRef, suffix string, at *time.Time) (*Path, os.Error) } + +func IsIndexedAttribute(attr string) bool { + switch attr { + case "camliRoot", "tag", "title": + return true + } + return false +} + +func IsFulltextAttribute(attr string) bool { + switch attr { + case "tag", "title": + return true + } + return false +} +