@@ -391,49 +391,68 @@ func (qs *queryState) handleValuePostings(ctx context.Context, args funcArgs) er
391391 key := x .DataKey (q .Attr , q .UidList .Uids [i ])
392392
393393 // Get or create the posting list for an entity, attribute combination.
394- pl , err := qs .cache .Get (key )
395- if err != nil {
396- return err
397- }
394+ var pl * posting.List
395+ pickMultiplePostings := q .ExpandAll || (listType && len (q .Langs ) == 0 )
396+
397+ var vals []types.Val
398+ fcs := & pb.FacetsList {FacetsList : make ([]* pb.Facets , 0 )} // TODO Figure out how it is stored
398399
399- // If count is being requested, there is no need to populate value and facets matrix.
400- if q .DoCount {
401- count , err := countForValuePostings (args , pl , facetsTree , listType )
402- if err != nil && err != posting .ErrNoValue {
400+ if pickMultiplePostings {
401+ pl , err = qs .cache .Get (key )
402+ if err != nil {
403403 return err
404404 }
405- out .Counts = append (out .Counts , uint32 (count ))
406- // Add an empty UID list to make later processing consistent.
407- out .UidMatrix = append (out .UidMatrix , & pb.List {})
408- continue
409- }
405+ // If count is being requested, there is no need to populate value and facets matrix.
406+ if q .DoCount {
407+ count , err := countForValuePostings (args , pl , facetsTree , listType )
408+ if err != nil && err != posting .ErrNoValue {
409+ return err
410+ }
411+ out .Counts = append (out .Counts , uint32 (count ))
412+ // Add an empty UID list to make later processing consistent.
413+ out .UidMatrix = append (out .UidMatrix , & pb.List {})
414+ continue
415+ }
410416
411- vals , fcs , err := retrieveValuesAndFacets (args , pl , facetsTree , listType )
412- switch {
413- case err == posting .ErrNoValue || (err == nil && len (vals ) == 0 ):
414- // This branch is taken when the value does not exist in the pl or
415- // the number of values retrieved is zero (there could still be facets).
416- // We add empty lists to the UidMatrix, FaceMatrix, ValueMatrix and
417- // LangMatrix so that all these data structure have predictable layouts.
418- out .UidMatrix = append (out .UidMatrix , & pb.List {})
419- out .FacetMatrix = append (out .FacetMatrix , & pb.FacetsList {})
420- out .ValueMatrix = append (out .ValueMatrix ,
421- & pb.ValueList {Values : []* pb.TaskValue {}})
422417 if q .ExpandAll {
423- // To keep the cardinality same as that of ValueMatrix.
424- out .LangMatrix = append (out .LangMatrix , & pb.LangList {})
418+ langTags , err := pl .GetLangTags (args .q .ReadTs )
419+ if err != nil {
420+ return err
421+ }
422+ out .LangMatrix = append (out .LangMatrix , & pb.LangList {Lang : langTags })
423+ }
424+
425+ vals , fcs , err = retrieveValuesAndFacets (args , pl , facetsTree , listType )
426+ switch {
427+ case err == posting .ErrNoValue || (err == nil && len (vals ) == 0 ):
428+ // This branch is taken when the value does not exist in the pl or
429+ // the number of values retrieved is zero (there could still be facets).
430+ // We add empty lists to the UidMatrix, FaceMatrix, ValueMatrix and
431+ // LangMatrix so that all these data structure have predictable layouts.
432+ out .UidMatrix = append (out .UidMatrix , & pb.List {})
433+ out .FacetMatrix = append (out .FacetMatrix , & pb.FacetsList {})
434+ out .ValueMatrix = append (out .ValueMatrix ,
435+ & pb.ValueList {Values : []* pb.TaskValue {}})
436+ if q .ExpandAll {
437+ // To keep the cardinality same as that of ValueMatrix.
438+ out .LangMatrix = append (out .LangMatrix , & pb.LangList {})
439+ }
440+ continue
441+ case err != nil :
442+ return err
443+ }
444+
445+ } else {
446+ pl , err = qs .cache .GetSingleItem (key )
447+ if err != nil {
448+ return err
425449 }
426- continue
427- case err != nil :
428- return err
429- }
430450
431- if q .ExpandAll {
432- langTags , err := pl .GetLangTags (args .q .ReadTs )
451+ val , err := pl .AllValues (q .ReadTs )
433452 if err != nil {
434453 return err
435454 }
436- out . LangMatrix = append (out . LangMatrix , & pb. LangList { Lang : langTags } )
455+ vals = append (vals , val ... )
437456 }
438457
439458 uidList := new (pb.List )
0 commit comments