From 6dbafbe0b4f1038105f730a47063748073250d36 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sun, 13 Mar 2011 12:18:00 -0700 Subject: [PATCH] mysqlindexer: claims table --- dev-indexer | 13 +++++++++++++ lib/go/mysqlindexer/receive.go | 28 ++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/dev-indexer b/dev-indexer index f656933b5..2f241d2de 100755 --- a/dev-indexer +++ b/dev-indexer @@ -55,6 +55,19 @@ if ($opt_wipe) { "size INTEGER NOT NULL, ". "type VARCHAR(100)". ")"); + + $dbh->do("CREATE TABLE claims (". + "blobref VARCHAR(128) NOT NULL PRIMARY KEY, ". + "signer VARCHAR(128) NOT NULL, ". + "date VARCHAR(40) NOT NULL, ". + "INDEX (signer, date), ". + "unverified CHAR(1) NULL, ". + "claim VARCHAR(50) NOT NULL, ". + "permanode VARCHAR(128) NOT NULL, ". + "INDEX (permanode), ". + "attr VARCHAR(128) NULL, ". + "value VARCHAR(128) NULL ". + ")"); } print "Starting blobserver with indexer on http://localhost:$port/ in $root\n"; diff --git a/lib/go/mysqlindexer/receive.go b/lib/go/mysqlindexer/receive.go index 841f62d57..5853f8e2e 100644 --- a/lib/go/mysqlindexer/receive.go +++ b/lib/go/mysqlindexer/receive.go @@ -35,7 +35,7 @@ const maxSniffSize = 1024 * 16 type blobSniffer struct { header []byte written int64 - camli schema.Superset + camli *schema.Superset mimeType *string } @@ -97,10 +97,12 @@ func (sn *blobSniffer) bufferIsCamliJson() bool { if len(buf) < 2 || buf[0] != '{' { return false } - err := json.Unmarshal(buf, &sn.camli) + camli := new(schema.Superset) + err := json.Unmarshal(buf, camli) if err != nil { return false } + sn.camli = camli return true } @@ -140,6 +142,28 @@ func (mi *Indexer) ReceiveBlob(blobRef *blobref.BlobRef, source io.Reader, mirro return } + if camli := sniffer.camli; camli != nil && camli.Type == "claim" { + if err = populateClaim(client, blobRef, camli); err != nil { + return + } + } + retsb = &blobref.SizedBlobRef{BlobRef: blobRef, Size: written} return } + +func populateClaim(client *mysql.Client, blobRef *blobref.BlobRef, camli *schema.Superset) (err os.Error) { + var stmt *mysql.Statement + if stmt, err = client.Prepare("INSERT INTO claims (blobref, signer, date, unverified, claim, permanode, attr, value) " + + "VALUES (?, ?, ?, 'Y', ?, ?, ?, ?)"); err != nil { + return + } + if err = stmt.BindParams(blobRef.String(), camli.Signer, camli.ClaimDate, + camli.ClaimType, camli.Permanode, camli.Attribute, camli.Value); err != nil { + return + } + if err = stmt.Execute(); err != nil { + return + } + return nil +} \ No newline at end of file