Skip to content

Commit 682c27f

Browse files
committed
fix: http client
1 parent 6bde3ef commit 682c27f

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

pkg/google/google.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,12 @@ func (ds *DirectoryService) GetUsersBatch(ctx context.Context, emails []string)
318318

319319
var allUsers []*admin.User
320320

321-
// Process emails in chunks to avoid overly complex OR queries
321+
slog.Debug("google: GetUsersBatch starting chunked processing", "total_emails", len(emails), "chunk_size", chunkSize) // Process emails in chunks to avoid overly complex OR queries
322322
for i := 0; i < len(emails); i += chunkSize {
323-
end := min(i+chunkSize, len(emails))
323+
end := i + chunkSize
324+
if end > len(emails) {
325+
end = len(emails)
326+
}
324327

325328
chunk := emails[i:end]
326329

@@ -332,6 +335,8 @@ func (ds *DirectoryService) GetUsersBatch(ctx context.Context, emails []string)
332335

333336
query := strings.Join(emailQueries, " OR ")
334337

338+
slog.Debug("google: processing chunk", "chunk_index", i/chunkSize+1, "chunk_size", len(chunk), "chunk_start", i)
339+
335340
// Execute ListUsers for this chunk
336341
users, err := ds.ListUsers(ctx, []string{query})
337342
if err != nil {
@@ -344,12 +349,27 @@ func (ds *DirectoryService) GetUsersBatch(ctx context.Context, emails []string)
344349
return nil, fmt.Errorf("google: both batch and individual calls failed: batch_error=%w, individual_error=%v", err, individualErr)
345350
}
346351
users = individualUsers
352+
} else if len(users) == 0 {
353+
// If chunk query succeeds but returns no users, also fall back to individual calls
354+
slog.Warn("google: GetUsersBatch chunk returned no users, falling back to individual calls for chunk",
355+
"chunk_size", len(chunk), "chunk_start", i)
356+
357+
individualUsers, individualErr := ds.getUsersIndividually(ctx, chunk)
358+
if individualErr != nil {
359+
slog.Warn("google: individual calls also failed for chunk", "error", individualErr)
360+
// Continue with empty users rather than failing completely
361+
} else {
362+
users = individualUsers
363+
}
347364
}
348365

349366
// Accumulate results from this chunk
350367
allUsers = append(allUsers, users...)
368+
slog.Debug("google: chunk completed", "chunk_users", len(users), "total_users_so_far", len(allUsers))
351369
}
352370

371+
slog.Debug("google: GetUsersBatch completed", "total_users_returned", len(allUsers), "total_emails_requested", len(emails))
372+
353373
return allUsers, nil
354374
}
355375

0 commit comments

Comments
 (0)