From 53310b9aa38a7c3fc42d6408f081f623ddb8d37f Mon Sep 17 00:00:00 2001 From: Caleb Roseland Date: Fri, 19 Apr 2024 16:08:30 -0500 Subject: [PATCH] Fix whitelist upload batching (#612) (#615) --- server/api.go | 2 ++ server/store/sqlstore/store.go | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/server/api.go b/server/api.go index a3554ff9d..2c9b0baf5 100644 --- a/server/api.go +++ b/server/api.go @@ -807,6 +807,8 @@ func (a *API) updateWhitelist(w http.ResponseWriter, r *http.Request) { return } + a.p.API.LogInfo("Whitelist updated", "size", len(ids)) + w.WriteHeader(http.StatusOK) w.Header().Set("Content-Type", "application/json") if err := json.NewEncoder(w).Encode(&UpdateWhitelistResult{ diff --git a/server/store/sqlstore/store.go b/server/store/sqlstore/store.go index 565246bfe..64314606e 100644 --- a/server/store/sqlstore/store.go +++ b/server/store/sqlstore/store.go @@ -1006,11 +1006,12 @@ func (s *SQLStore) SetWhitelist(userIDs []string, batchSize int) error { for i, id := range userIDs { currentBatch = append(currentBatch, id) if len(currentBatch) >= batchSize || i == len(userIDs)-1 { + // batch threshold met, or end of list if err = s.storeUsersInWhitelist(currentBatch, tx); err != nil { s.api.LogDebug("Error adding batched users to whitelist", "error", err.Error(), "userIds", currentBatch) return err } - clear(currentBatch) + currentBatch = nil } }