Skip to content

Commit 6db9515

Browse files
author
VASHISTH Chandramouli
committed
keyset pagination on /users for >=16.5; fallback to offset
1 parent eccec79 commit 6db9515

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

backend/plugins/gitlab/tasks/account_collector.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func init() {
3636
}
3737

3838
const RAW_USER_TABLE = "gitlab_api_users"
39+
const KEYSET_MIN_VERSION = "v16.5.0"
3940

4041
var CollectAccountsMeta = plugin.SubTaskMeta{
4142
Name: "Collect Users",
@@ -62,6 +63,14 @@ func CollectAccounts(taskCtx plugin.SubTaskContext) errors.Error {
6263
urlTemplate = "/users"
6364
}
6465

66+
useKeyset := false
67+
if urlTemplate == "/users" && semver.IsValid(apiVersion) && semver.Compare(data.ApiClient.GetData(models.GitlabApiClientData_ApiVersion).(string), KEYSET_MIN_VERSION)>= 0 {
68+
useKeyset = true
69+
} else if urlTemplate == "/users" && !semver.IsValid(apiVersion) {
70+
// If version unknown, be conservative for CE 11–16.4: default to offset
71+
logger.Debug("GitLab version is unknown/invalid; falling back to offset pagination for /users")
72+
}
73+
6574
var lastID int
6675

6776
collector, err := api.NewApiCollector(api.ApiCollectorArgs{
@@ -71,7 +80,8 @@ func CollectAccounts(taskCtx plugin.SubTaskContext) errors.Error {
7180
PageSize: 100,
7281
Query: func(reqData *api.RequestData) (url.Values, errors.Error) {
7382
query := url.Values{}
74-
if urlTemplate == "/users" {
83+
// Use keyset only when gated true and only on /users endpoint
84+
if useKeyset && urlTemplate == "/users" {
7585
query.Set("pagination", "keyset")
7686
query.Set("order_by", "id")
7787
query.Set("sort", "asc")

0 commit comments

Comments
 (0)