diff --git a/client/api.go b/client/api.go index 8d5a30ef..10f4e21b 100644 --- a/client/api.go +++ b/client/api.go @@ -147,22 +147,24 @@ func (a api) List(ctx context.Context, result interface{}) error { return ErrNotFound } - // If given a null slice, fill it in the cache table completely, if not, just up to - // its capability - if resultVal.IsNil() || resultVal.Cap() == 0 { - resultVal.Set(reflect.MakeSlice(resultVal.Type(), 0, tableCache.Len())) - } - i := resultVal.Len() - var rows map[string]model.Model if a.cond != nil { rows, err = a.cond.Matches() if err != nil { return err } + if resultVal.IsNil() || resultVal.Cap() == 0 { + resultVal.Set(reflect.MakeSlice(resultVal.Type(), 0, len(rows))) + } } else { rows = tableCache.Rows() + // If given a null slice, fill it in the cache table completely, if not, just up to + // its capability. + if resultVal.IsNil() || resultVal.Cap() == 0 { + resultVal.Set(reflect.MakeSlice(resultVal.Type(), 0, tableCache.Len())) + } } + i := resultVal.Len() for _, row := range rows { if i >= resultVal.Cap() {