Skip to content

Commit 9cbee90

Browse files
Added one more optimization
1 parent efdfa9d commit 9cbee90

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

posting/lists.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,18 @@ func (lc *LocalCache) getInternal(key []byte, readFromDisk bool) (*List, error)
202202
lc.RLock()
203203
defer lc.RUnlock()
204204
if lc.plists == nil {
205-
return getNew(key, pstore, lc.startTs)
205+
if readFromDisk {
206+
return getNew(key, pstore, lc.startTs)
207+
} else {
208+
pl := &List{
209+
key: key,
210+
plist: new(pb.PostingList),
211+
}
212+
if delta, ok := lc.deltas[string(key)]; ok && len(delta) > 0 {
213+
pl.setMutation(lc.startTs, delta)
214+
}
215+
return pl, nil
216+
}
206217
}
207218
return nil, nil
208219
}

worker/task.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,8 @@ func (qs *queryState) handleValuePostings(ctx context.Context, args funcArgs) er
376376

377377
outputs := make([]*pb.Result, numGo)
378378
listType := schema.State().IsList(q.Attr)
379+
pickMultiplePostings := q.DoCount || q.ExpandAll || listType || len(q.Langs) > 0
380+
//pickMultiplePostings := true
379381

380382
calculate := func(start, end int) error {
381383
x.AssertTrue(start%width == 0)
@@ -391,24 +393,23 @@ func (qs *queryState) handleValuePostings(ctx context.Context, args funcArgs) er
391393
key := x.DataKey(q.Attr, q.UidList.Uids[i])
392394

393395
// Get or create the posting list for an entity, attribute combination.
394-
pickMultiplePostings := q.DoCount || q.ExpandAll || listType || len(q.Langs) > 0
395396

396397
var vals []types.Val
397398
fcs := &pb.FacetsList{FacetsList: make([]*pb.Facets, 0)} // TODO Figure out how it is stored
398399

399400
if !pickMultiplePostings {
400401
pl, _ := qs.cache.GetSinglePosting(key)
401-
for _, p := range pl.Postings {
402-
vals = append(vals, types.Val{
402+
vals = make([]types.Val, len(pl.Postings))
403+
for i, p := range pl.Postings {
404+
vals[i] = types.Val{
403405
Tid: types.TypeID(p.ValType),
404406
Value: p.Value,
405-
})
407+
}
406408

407409
if q.FacetParam != nil {
408410
fcs.FacetsList = append(fcs.FacetsList, &pb.Facets{Facets: facets.CopyFacets(p.Facets, q.FacetParam)})
409411
}
410412
}
411-
412413
} else {
413414
pl, err := qs.cache.Get(key)
414415
if err != nil {

0 commit comments

Comments
 (0)