Fix record fetching ending prematurely due to RBAC
If nothing from a chunk was included due to RBAC, the fetching ended prematurelly. Track both fetched and filtered items to overcome this.
This commit is contained in:
parent
5fbd8ee97f
commit
8e03ea56ef
@ -3,6 +3,7 @@ package dalutils
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/cortezaproject/corteza/server/compose/types"
|
"github.com/cortezaproject/corteza/server/compose/types"
|
||||||
"github.com/cortezaproject/corteza/server/pkg/dal"
|
"github.com/cortezaproject/corteza/server/pkg/dal"
|
||||||
"github.com/cortezaproject/corteza/server/pkg/filter"
|
"github.com/cortezaproject/corteza/server/pkg/filter"
|
||||||
@ -131,6 +132,7 @@ func drainIterator(ctx context.Context, iter dal.Iterator, mod *types.Module, f
|
|||||||
var (
|
var (
|
||||||
ok bool
|
ok bool
|
||||||
fetched uint
|
fetched uint
|
||||||
|
filtered uint
|
||||||
r *types.Record
|
r *types.Record
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -144,6 +146,7 @@ func drainIterator(ctx context.Context, iter dal.Iterator, mod *types.Module, f
|
|||||||
for f.Limit == 0 || uint(len(set)) < f.Limit {
|
for f.Limit == 0 || uint(len(set)) < f.Limit {
|
||||||
// reset counters every drain
|
// reset counters every drain
|
||||||
fetched = 0
|
fetched = 0
|
||||||
|
filtered = 0
|
||||||
|
|
||||||
err = WalkIterator(ctx, iter, mod, func(r *types.Record) error {
|
err = WalkIterator(ctx, iter, mod, func(r *types.Record) error {
|
||||||
// check fetched record
|
// check fetched record
|
||||||
@ -151,6 +154,7 @@ func drainIterator(ctx context.Context, iter dal.Iterator, mod *types.Module, f
|
|||||||
if ok, err = f.Check(r); err != nil {
|
if ok, err = f.Check(r); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if !ok {
|
} else if !ok {
|
||||||
|
filtered++
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -166,11 +170,12 @@ func drainIterator(ctx context.Context, iter dal.Iterator, mod *types.Module, f
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if fetched == 0 || f.Limit == 0 || (0 < f.Limit && fetched < f.Limit) {
|
total := fetched + filtered
|
||||||
|
if total == 0 || f.Limit == 0 || (0 < f.Limit && total < f.Limit) {
|
||||||
// do not re-fetch if:
|
// do not re-fetch if:
|
||||||
// 1) nothing was fetch in the previous run
|
// 1) nothing was fetch in the previous run
|
||||||
// 2) there was no limit (everything was fetched)
|
// 2) there was no limit (everything was fetched)
|
||||||
// 3) there are less fetched items then value of limit
|
// 3) there are less total (fetched and filtered) items then value of limit
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user