refactor(unified-storage): extract list iterator and add tests (#105600)
This commit is contained in:
@@ -585,73 +585,6 @@ func (b *backend) ListIterator(ctx context.Context, req *resourcepb.ListRequest,
|
||||
return b.listLatest(ctx, req, cb)
|
||||
}
|
||||
|
||||
type listIter struct {
|
||||
rows db.Rows
|
||||
offset int64
|
||||
listRV int64
|
||||
sortAsc bool
|
||||
|
||||
// any error
|
||||
err error
|
||||
|
||||
// The row
|
||||
guid string
|
||||
rv int64
|
||||
value []byte
|
||||
namespace string
|
||||
resource string
|
||||
group string
|
||||
name string
|
||||
folder string
|
||||
}
|
||||
|
||||
// ContinueToken implements resource.ListIterator.
|
||||
func (l *listIter) ContinueToken() string {
|
||||
return resource.ContinueToken{ResourceVersion: l.listRV, StartOffset: l.offset, SortAscending: l.sortAsc}.String()
|
||||
}
|
||||
|
||||
func (l *listIter) ContinueTokenWithCurrentRV() string {
|
||||
return resource.ContinueToken{ResourceVersion: l.rv, StartOffset: l.offset, SortAscending: l.sortAsc}.String()
|
||||
}
|
||||
|
||||
func (l *listIter) Error() error {
|
||||
return l.err
|
||||
}
|
||||
|
||||
func (l *listIter) Name() string {
|
||||
return l.name
|
||||
}
|
||||
|
||||
func (l *listIter) Namespace() string {
|
||||
return l.namespace
|
||||
}
|
||||
|
||||
func (l *listIter) Folder() string {
|
||||
return l.folder
|
||||
}
|
||||
|
||||
// ResourceVersion implements resource.ListIterator.
|
||||
func (l *listIter) ResourceVersion() int64 {
|
||||
return l.rv
|
||||
}
|
||||
|
||||
// Value implements resource.ListIterator.
|
||||
func (l *listIter) Value() []byte {
|
||||
return l.value
|
||||
}
|
||||
|
||||
// Next implements resource.ListIterator.
|
||||
func (l *listIter) Next() bool {
|
||||
if l.rows.Next() {
|
||||
l.offset++
|
||||
l.err = l.rows.Scan(&l.guid, &l.rv, &l.namespace, &l.resource, &l.group, &l.name, &l.folder, &l.value)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
var _ resource.ListIterator = (*listIter)(nil)
|
||||
|
||||
// listLatest fetches the resources from the resource table.
|
||||
func (b *backend) listLatest(ctx context.Context, req *resourcepb.ListRequest, cb func(resource.ListIterator) error) (int64, error) {
|
||||
ctx, span := b.tracer.Start(ctx, tracePrefix+"listLatest")
|
||||
|
||||
Reference in New Issue
Block a user