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 (
"container/list"
"fmt"
)
// TODO(kortschak) Reimplement without container/list.
@ -49,9 +48,6 @@ func (lru *cache) Put(key string, value interface{}) {
lru.removeOldest()
}
lru.priority.PushFront(kv{key: key, value: value})
if lru.priority == nil {
fmt.Println("wat")
}
lru.cache[key] = lru.priority.Front()
}
@ -60,7 +56,7 @@ func (lru *cache) Get(key string) (interface{}, bool) {
lru.priority.MoveToFront(element)
return element.Value.(kv).value, true
}
return "", false
return nil, false
}
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) {
var size int
var err error
bytes, err := bson.Marshal(constraint)
if err != nil {
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)
var firstmongo *Iterator
var mongoIt *Iterator
for _, it := range it.SubIterators() {
switch it.Type() {
case mongoType:
if firstmongo == nil {
firstmongo = it.(*Iterator)
if mongoIt == nil {
mongoIt = it.(*Iterator)
} else {
newAnd.AddSubIterator(it)
}
@ -63,30 +63,30 @@ func (qs *QuadStore) optimizeAndIterator(it *iterator.And) (graph.Iterator, bool
newAnd.AddSubIterator(it)
}
}
mongostats := firstmongo.Stats()
stats := mongoIt.Stats()
lset := []graph.Linkage{
{
Dir: firstmongo.dir,
Values: []graph.Value{qs.ValueOf(firstmongo.name)},
Dir: mongoIt.dir,
Values: []graph.Value{qs.ValueOf(mongoIt.name)},
},
}
ltocount := 0
n := 0
for _, it := range it.SubIterators() {
if it.Type() == graph.LinksTo {
lto := it.(*iterator.LinksTo)
// Is it more effective to do the replacement, or let the mongo check the linksto?
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
}
newLto := NewLinksTo(qs, lto.SubIterators()[0], "quads", lto.Direction(), lset)
newAnd.AddSubIterator(newLto)
ltocount++
n++
}
}
if ltocount == 0 {
if n == 0 {
return it, false
}