Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: User data source times out on getting all users - add pagination #146

Merged
merged 2 commits into from
May 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 31 additions & 16 deletions codefresh/cfclient/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cfclient

import (
"fmt"
"log"
"strings"
)

Expand Down Expand Up @@ -222,25 +221,41 @@ func (client *Client) DeleteUserAsAccountAdmin(accountId, userId string) error {

func (client *Client) GetAllUsers() (*[]User, error) {

opts := RequestOptions{
Path: "/admin/user",
Method: "GET",
}
limitPerQuery := 100
bIsDone := false
nPageIndex := 1

resp, err := client.RequestAPI(&opts)
if err != nil {
return nil, err
}
var allUsers []User

var users []User
respStr := string(resp)
log.Printf("[INFO] GetAllUsers resp: %s", respStr)
err = DecodeResponseInto(resp, &users)
if err != nil {
return nil, err
for !bIsDone {
var userPaginatedResp struct{Docs []User `json:"docs"`}

opts := RequestOptions{
Path: fmt.Sprintf("/admin/user?limit=%d&page=%d", limitPerQuery, nPageIndex),
Method: "GET",
}

resp, err := client.RequestAPI(&opts)

if err != nil {
return nil, err
}

err = DecodeResponseInto(resp, &userPaginatedResp)

if err != nil {
return nil, err
}

if len(userPaginatedResp.Docs) > 0 {
allUsers = append(allUsers,userPaginatedResp.Docs...)
nPageIndex++
} else {
bIsDone = true
}
}

return &users, nil
return &allUsers, nil
}

func (client *Client) GetUserByID(userId string) (*User, error) {
Expand Down
Loading