Skip to content

Commit d560f1c

Browse files
committed
Always do a range read for ListWindowsDesktops
1 parent 80b2d2f commit d560f1c

File tree

1 file changed

+15
-30
lines changed

1 file changed

+15
-30
lines changed

lib/services/local/desktops.go

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -237,39 +237,24 @@ func (s *WindowsDesktopService) ListWindowsDesktops(ctx context.Context, req typ
237237
filter.PredicateExpression = expression
238238
}
239239

240-
// do a point-read instead of a range-read if a filter is provided
241-
if req.HostID != "" && req.Name != "" {
242-
desktop, err := s.getWindowsDesktop(ctx, req.Name, req.HostID)
243-
if trace.IsNotFound(err) {
244-
return &types.ListWindowsDesktopsResponse{}, nil
245-
} else if err != nil {
246-
return nil, trace.Wrap(err)
247-
}
248-
249-
match, err := services.MatchResourceByFilters(desktop, filter, nil /* ignore dup matches */)
250-
if err != nil {
251-
return nil, trace.Wrap(err)
252-
}
253-
254-
if !match {
255-
return &types.ListWindowsDesktopsResponse{}, nil
256-
}
257-
258-
return &types.ListWindowsDesktopsResponse{
259-
Desktops: []types.WindowsDesktop{desktop},
260-
}, nil
240+
var rangeStart, rangeEnd backend.Key
241+
switch {
242+
case req.Name != "" && req.HostID != "":
243+
rangeStart = backend.NewKey(windowsDesktopsPrefix, req.HostID, req.Name)
244+
rangeEnd = rangeStart
245+
case req.HostID != "":
246+
rangeStart = backend.ExactKey(windowsDesktopsPrefix, req.HostID)
247+
rangeEnd = backend.RangeEnd(rangeStart)
248+
default:
249+
rangeStart = backend.ExactKey(windowsDesktopsPrefix)
250+
rangeEnd = backend.RangeEnd(rangeStart)
261251
}
262252

263-
var rangeStart, rangeEnd backend.Key
264-
if req.HostID != "" && req.Name == "" {
265-
rangeStart = backend.NewKey(windowsDesktopsPrefix, req.HostID)
266-
if req.StartKey != "" {
267-
rangeStart = backend.NewKey(windowsDesktopsPrefix, req.StartKey)
253+
if req.StartKey != "" {
254+
k := backend.NewKey(windowsDesktopsPrefix, req.StartKey)
255+
if k.Compare(rangeStart) > 0 {
256+
rangeStart = k
268257
}
269-
rangeEnd = backend.RangeEnd(rangeStart)
270-
} else {
271-
rangeStart = backend.NewKey(windowsDesktopsPrefix, req.StartKey)
272-
rangeEnd = backend.RangeEnd(backend.ExactKey(windowsDesktopsPrefix))
273258
}
274259

275260
// Get most limit+1 results to determine if there will be a next key.

0 commit comments

Comments
 (0)