This commit is contained in:
Barak Michener 2015-04-25 19:00:18 -04:00
parent 355c8ee6bc
commit c3c5fe50c1
3 changed files with 11 additions and 16 deletions

View file

@ -16,7 +16,6 @@ package mongo
import ( import (
"container/list" "container/list"
"fmt"
) )
// TODO(kortschak) Reimplement without container/list. // TODO(kortschak) Reimplement without container/list.
@ -49,9 +48,6 @@ func (lru *cache) Put(key string, value interface{}) {
lru.removeOldest() lru.removeOldest()
} }
lru.priority.PushFront(kv{key: key, value: value}) lru.priority.PushFront(kv{key: key, value: value})
if lru.priority == nil {
fmt.Println("wat")
}
lru.cache[key] = lru.priority.Front() lru.cache[key] = lru.priority.Front()
} }
@ -60,7 +56,7 @@ func (lru *cache) Get(key string) (interface{}, bool) {
lru.priority.MoveToFront(element) lru.priority.MoveToFront(element)
return element.Value.(kv).value, true return element.Value.(kv).value, true
} }
return "", false return nil, false
} }
func (lru *cache) removeOldest() { func (lru *cache) removeOldest() {

View file

@ -382,7 +382,6 @@ func (qs *QuadStore) Type() string {
func (qs *QuadStore) getSize(collection string, constraint bson.M) (int64, error) { func (qs *QuadStore) getSize(collection string, constraint bson.M) (int64, error) {
var size int var size int
var err error
bytes, err := bson.Marshal(constraint) bytes, err := bson.Marshal(constraint)
if err != nil { if err != nil {
glog.Errorf("Couldn't marshal internal constraint") glog.Errorf("Couldn't marshal internal constraint")

View file

@ -48,12 +48,12 @@ func (qs *QuadStore) optimizeAndIterator(it *iterator.And) (graph.Iterator, bool
} }
newAnd := iterator.NewAnd(qs) newAnd := iterator.NewAnd(qs)
var firstmongo *Iterator var mongoIt *Iterator
for _, it := range it.SubIterators() { for _, it := range it.SubIterators() {
switch it.Type() { switch it.Type() {
case mongoType: case mongoType:
if firstmongo == nil { if mongoIt == nil {
firstmongo = it.(*Iterator) mongoIt = it.(*Iterator)
} else { } else {
newAnd.AddSubIterator(it) newAnd.AddSubIterator(it)
} }
@ -63,30 +63,30 @@ func (qs *QuadStore) optimizeAndIterator(it *iterator.And) (graph.Iterator, bool
newAnd.AddSubIterator(it) newAnd.AddSubIterator(it)
} }
} }
mongostats := firstmongo.Stats() stats := mongoIt.Stats()
lset := []graph.Linkage{ lset := []graph.Linkage{
{ {
Dir: firstmongo.dir, Dir: mongoIt.dir,
Values: []graph.Value{qs.ValueOf(firstmongo.name)}, Values: []graph.Value{qs.ValueOf(mongoIt.name)},
}, },
} }
ltocount := 0 n := 0
for _, it := range it.SubIterators() { for _, it := range it.SubIterators() {
if it.Type() == graph.LinksTo { if it.Type() == graph.LinksTo {
lto := it.(*iterator.LinksTo) lto := it.(*iterator.LinksTo)
// Is it more effective to do the replacement, or let the mongo check the linksto? // Is it more effective to do the replacement, or let the mongo check the linksto?
ltostats := lto.Stats() ltostats := lto.Stats()
if (ltostats.ContainsCost+mongostats.NextCost)*mongostats.Size > (ltostats.NextCost+mongostats.ContainsCost)*ltostats.Size { if (ltostats.ContainsCost+stats.NextCost)*stats.Size > (ltostats.NextCost+stats.ContainsCost)*ltostats.Size {
continue continue
} }
newLto := NewLinksTo(qs, lto.SubIterators()[0], "quads", lto.Direction(), lset) newLto := NewLinksTo(qs, lto.SubIterators()[0], "quads", lto.Direction(), lset)
newAnd.AddSubIterator(newLto) newAnd.AddSubIterator(newLto)
ltocount++ n++
} }
} }
if ltocount == 0 { if n == 0 {
return it, false return it, false
} }