mirror of https://github.com/perkeep/perkeep.git
mysqlindexer: claims table
This commit is contained in:
parent
61e5ffa5ee
commit
6dbafbe0b4
13
dev-indexer
13
dev-indexer
|
@ -55,6 +55,19 @@ if ($opt_wipe) {
|
||||||
"size INTEGER NOT NULL, ".
|
"size INTEGER NOT NULL, ".
|
||||||
"type VARCHAR(100)".
|
"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";
|
print "Starting blobserver with indexer on http://localhost:$port/ in $root\n";
|
||||||
|
|
|
@ -35,7 +35,7 @@ const maxSniffSize = 1024 * 16
|
||||||
type blobSniffer struct {
|
type blobSniffer struct {
|
||||||
header []byte
|
header []byte
|
||||||
written int64
|
written int64
|
||||||
camli schema.Superset
|
camli *schema.Superset
|
||||||
mimeType *string
|
mimeType *string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,10 +97,12 @@ func (sn *blobSniffer) bufferIsCamliJson() bool {
|
||||||
if len(buf) < 2 || buf[0] != '{' {
|
if len(buf) < 2 || buf[0] != '{' {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
err := json.Unmarshal(buf, &sn.camli)
|
camli := new(schema.Superset)
|
||||||
|
err := json.Unmarshal(buf, camli)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
sn.camli = camli
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,6 +142,28 @@ func (mi *Indexer) ReceiveBlob(blobRef *blobref.BlobRef, source io.Reader, mirro
|
||||||
return
|
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}
|
retsb = &blobref.SizedBlobRef{BlobRef: blobRef, Size: written}
|
||||||
return
|
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
|
||||||
|
}
|
Loading…
Reference in New Issue