runservice: fix query when grouping by path

When grouping by group path we have to apply the filter to the group by using
HAVING and not using WHERE
This commit is contained in:
Simone Gotti 2019-05-23 23:21:45 +02:00
parent 03a0d38b10
commit c0a165de31
1 changed files with 15 additions and 6 deletions

View File

@ -38,12 +38,12 @@ import (
"github.com/sorintlab/agola/internal/services/runservice/store"
"github.com/sorintlab/agola/internal/services/runservice/types"
"github.com/sorintlab/agola/internal/util"
"go.uber.org/zap"
sq "github.com/Masterminds/squirrel"
etcdclientv3 "go.etcd.io/etcd/clientv3"
etcdclientv3rpc "go.etcd.io/etcd/etcdserver/api/v3rpc/rpctypes"
"go.etcd.io/etcd/mvcc/mvccpb"
"go.uber.org/zap"
errors "golang.org/x/xerrors"
)
@ -1234,6 +1234,14 @@ func (r *ReadDB) getRunsFilteredQuery(phaseFilter []types.RunPhase, groups []str
s = s.Where(sq.Eq{"phase": phaseFilter})
}
if startRunID != "" {
if lastRun {
switch sortOrder {
case types.SortOrderAsc:
s = s.Having(sq.Gt{"run.id": startRunID})
case types.SortOrderDesc:
s = s.Having(sq.Lt{"run.id": startRunID})
}
} else {
switch sortOrder {
case types.SortOrderAsc:
s = s.Where(sq.Gt{"run.id": startRunID})
@ -1241,6 +1249,7 @@ func (r *ReadDB) getRunsFilteredQuery(phaseFilter []types.RunPhase, groups []str
s = s.Where(sq.Lt{"run.id": startRunID})
}
}
}
if limit > 0 {
s = s.Limit(uint64(limit))
}