Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iterate keys instead of fetching #673

Merged
merged 3 commits into from
Oct 18, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions shared/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ func LoadTestRunKeys(
from *time.Time,
to *time.Time,
limit *int) (result []*datastore.Key, err error) {
baseQuery := datastore.
NewQuery("TestRun").
Limit(MaxCountMaxValue)
baseQuery := datastore.NewQuery("TestRun")
if !IsLatest(sha) {
baseQuery = baseQuery.Filter("Revision =", sha)
}
Expand Down Expand Up @@ -73,21 +71,20 @@ func LoadTestRunKeys(
query = query.Filter("TimeStart <", *to)
}

fetched, err := query.KeysOnly().GetAll(ctx, nil)
if err != nil {
return nil, err
}
var keys []*datastore.Key
for _, key := range fetched {
if limit == nil || *limit > len(keys) && len(keys) < MaxCountMaxValue {
if prefiltered == nil || (*prefiltered).Contains(key.String()) {
keys = append(keys, key)
}
iter := query.KeysOnly().Run(ctx)
for {
key, err := iter.Next(nil)
if err == datastore.Done {
break
} else if err != nil {
return result, err
} else if (limit != nil && len(keys) >= *limit) || len(keys) >= MaxCountMaxValue {
break
} else if prefiltered != nil && !(*prefiltered).Contains(key.String()) {
continue
}
}

if limit != nil && len(keys) > *limit {
keys = keys[:*limit]
keys = append(keys, key)
}
result = append(result, keys...)
}
Expand Down