Canonicalise mongo receiver names

Remove redundant Mongo infixes that were miseed previously.
This commit is contained in:
kortschak 2014-06-28 21:51:32 +09:30
parent dc62d4f32c
commit 3831aad364
2 changed files with 44 additions and 44 deletions

View file

@ -38,7 +38,7 @@ type Iterator struct {
collection string collection string
} }
func NewMongoIterator(ts *TripleStore, collection string, dir string, val graph.TSVal) *Iterator { func NewIterator(ts *TripleStore, collection string, dir string, val graph.TSVal) *Iterator {
var m Iterator var m Iterator
graph.BaseIteratorInit(&m.BaseIterator) graph.BaseIteratorInit(&m.BaseIterator)
@ -70,7 +70,7 @@ func NewMongoIterator(ts *TripleStore, collection string, dir string, val graph.
return &m return &m
} }
func NewMongoAllIterator(ts *TripleStore, collection string) *Iterator { func NewAllIterator(ts *TripleStore, collection string) *Iterator {
var m Iterator var m Iterator
m.ts = ts m.ts = ts
m.dir = "all" m.dir = "all"
@ -88,91 +88,91 @@ func NewMongoAllIterator(ts *TripleStore, collection string) *Iterator {
return &m return &m
} }
func (m *Iterator) Reset() { func (it *Iterator) Reset() {
m.iter.Close() it.iter.Close()
m.iter = m.ts.db.C(m.collection).Find(m.constraint).Iter() it.iter = it.ts.db.C(it.collection).Find(it.constraint).Iter()
} }
func (m *Iterator) Close() { func (it *Iterator) Close() {
m.iter.Close() it.iter.Close()
} }
func (m *Iterator) Clone() graph.Iterator { func (it *Iterator) Clone() graph.Iterator {
var newM graph.Iterator var newM graph.Iterator
if m.isAll { if it.isAll {
newM = NewMongoAllIterator(m.ts, m.collection) newM = NewAllIterator(it.ts, it.collection)
} else { } else {
newM = NewMongoIterator(m.ts, m.collection, m.dir, m.hash) newM = NewIterator(it.ts, it.collection, it.dir, it.hash)
} }
newM.CopyTagsFrom(m) newM.CopyTagsFrom(it)
return newM return newM
} }
func (m *Iterator) Next() (graph.TSVal, bool) { func (it *Iterator) Next() (graph.TSVal, bool) {
var result struct { var result struct {
Id string "_id" Id string "_id"
//Sub string "Sub" //Sub string "Sub"
//Pred string "Pred" //Pred string "Pred"
//Obj string "Obj" //Obj string "Obj"
} }
found := m.iter.Next(&result) found := it.iter.Next(&result)
if !found { if !found {
err := m.iter.Err() err := it.iter.Err()
if err != nil { if err != nil {
glog.Errorln("Error Nexting Iterator: ", err) glog.Errorln("Error Nexting Iterator: ", err)
} }
return nil, false return nil, false
} }
m.Last = result.Id it.Last = result.Id
return result.Id, true return result.Id, true
} }
func (m *Iterator) Check(v graph.TSVal) bool { func (it *Iterator) Check(v graph.TSVal) bool {
graph.CheckLogIn(m, v) graph.CheckLogIn(it, v)
if m.isAll { if it.isAll {
m.Last = v it.Last = v
return graph.CheckLogOut(m, v, true) return graph.CheckLogOut(it, v, true)
} }
var offset int var offset int
switch m.dir { switch it.dir {
case "s": case "s":
offset = 0 offset = 0
case "p": case "p":
offset = (m.ts.hasher.Size() * 2) offset = (it.ts.hasher.Size() * 2)
case "o": case "o":
offset = (m.ts.hasher.Size() * 2) * 2 offset = (it.ts.hasher.Size() * 2) * 2
case "c": case "c":
offset = (m.ts.hasher.Size() * 2) * 3 offset = (it.ts.hasher.Size() * 2) * 3
} }
val := v.(string)[offset : m.ts.hasher.Size()*2+offset] val := v.(string)[offset : it.ts.hasher.Size()*2+offset]
if val == m.hash { if val == it.hash {
m.Last = v it.Last = v
return graph.CheckLogOut(m, v, true) return graph.CheckLogOut(it, v, true)
} }
return graph.CheckLogOut(m, v, false) return graph.CheckLogOut(it, v, false)
} }
func (m *Iterator) Size() (int64, bool) { func (it *Iterator) Size() (int64, bool) {
return m.size, true return it.size, true
} }
func (m *Iterator) Type() string { func (it *Iterator) Type() string {
if m.isAll { if it.isAll {
return "all" return "all"
} }
return "mongo" return "mongo"
} }
func (m *Iterator) Sorted() bool { return true } func (it *Iterator) Sorted() bool { return true }
func (m *Iterator) Optimize() (graph.Iterator, bool) { return m, false } func (it *Iterator) Optimize() (graph.Iterator, bool) { return it, false }
func (m *Iterator) DebugString(indent int) string { func (it *Iterator) DebugString(indent int) string {
size, _ := m.Size() size, _ := it.Size()
return fmt.Sprintf("%s(%s size:%d %s %s)", strings.Repeat(" ", indent), m.Type(), size, m.hash, m.name) return fmt.Sprintf("%s(%s size:%d %s %s)", strings.Repeat(" ", indent), it.Type(), size, it.hash, it.name)
} }
func (m *Iterator) GetStats() *graph.IteratorStats { func (it *Iterator) GetStats() *graph.IteratorStats {
size, _ := m.Size() size, _ := it.Size()
return &graph.IteratorStats{ return &graph.IteratorStats{
CheckCost: 1, CheckCost: 1,
NextCost: 5, NextCost: 5,

View file

@ -216,15 +216,15 @@ func (ts *TripleStore) GetTriple(val graph.TSVal) *graph.Triple {
} }
func (ts *TripleStore) GetTripleIterator(dir string, val graph.TSVal) graph.Iterator { func (ts *TripleStore) GetTripleIterator(dir string, val graph.TSVal) graph.Iterator {
return NewMongoIterator(ts, "triples", dir, val) return NewIterator(ts, "triples", dir, val)
} }
func (ts *TripleStore) GetNodesAllIterator() graph.Iterator { func (ts *TripleStore) GetNodesAllIterator() graph.Iterator {
return NewMongoAllIterator(ts, "nodes") return NewAllIterator(ts, "nodes")
} }
func (ts *TripleStore) GetTriplesAllIterator() graph.Iterator { func (ts *TripleStore) GetTriplesAllIterator() graph.Iterator {
return NewMongoAllIterator(ts, "triples") return NewAllIterator(ts, "triples")
} }
func (ts *TripleStore) GetIdFor(s string) graph.TSVal { func (ts *TripleStore) GetIdFor(s string) graph.TSVal {