fix: several client list bugs
This commit is contained in:
parent
22fee5b76f
commit
305f46ccbe
|
@ -55,6 +55,11 @@ func handleClients(r *http.Request, w http.ResponseWriter, s *state) {
|
|||
return
|
||||
}
|
||||
|
||||
// Make sure the requested page does not exceed the max.
|
||||
if reqdata.Limit > MAX_DATA_PAGE_SIZE {
|
||||
reqdata.Limit = MAX_DATA_PAGE_SIZE
|
||||
}
|
||||
|
||||
// Collect necessary information.
|
||||
clients := s.GetClients(reqdata.Offset, reqdata.Limit)
|
||||
|
||||
|
|
|
@ -18,6 +18,8 @@ const (
|
|||
STATE_CLEANUP_INTERVAL = 30 * time.Second
|
||||
STATE_CLIENT_EXPIRY_DELAY = proto.HEARTBEAT_MARK_DEAD_DELAY
|
||||
STATE_REQUEST_EXPIRY_DELAY = 10 * time.Minute
|
||||
|
||||
MAX_DATA_PAGE_SIZE = 200
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
|
|
|
@ -81,6 +81,13 @@ func (l *clientList) GetPage(offset, limit int) []*client {
|
|||
return []*client{}
|
||||
}
|
||||
|
||||
// If the remainder of the client list after the offset is
|
||||
// smaller than the limit, reduce the limit to the size of that
|
||||
// remainder to avoid nulls in the returned data.
|
||||
if maxLimit := len(l.clients) - offset; maxLimit < limit {
|
||||
limit = maxLimit
|
||||
}
|
||||
|
||||
page := make([]*client, limit)
|
||||
current := l.head
|
||||
for i := 0; i < offset+limit; i++ {
|
||||
|
@ -88,8 +95,8 @@ func (l *clientList) GetPage(offset, limit int) []*client {
|
|||
break
|
||||
}
|
||||
|
||||
if i > offset && i < offset+limit {
|
||||
page = append(page, current)
|
||||
if i >= offset && i < offset+limit {
|
||||
page[i-offset] = current
|
||||
}
|
||||
|
||||
current = current.next
|
||||
|
|
Loading…
Reference in New Issue
Block a user