From a855d8c8a80340f5e105b815e507ed8ffe9e9ad1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Kaan=20K=C3=B6se?= Date: Wed, 8 Apr 2026 13:09:04 +0200 Subject: [PATCH] Gmail calendar actions fix. --- Wino.Core/Synchronizers/GmailSynchronizer.cs | 40 +++++++++----------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/Wino.Core/Synchronizers/GmailSynchronizer.cs b/Wino.Core/Synchronizers/GmailSynchronizer.cs index dddda1dd..b515d4d7 100644 --- a/Wino.Core/Synchronizers/GmailSynchronizer.cs +++ b/Wino.Core/Synchronizers/GmailSynchronizer.cs @@ -10,7 +10,6 @@ using System.Web; using CommunityToolkit.Mvvm.Messaging; using Google; using Google.Apis.Calendar.v3.Data; -using Google.Apis.Drive.v3; using Google.Apis.Gmail.v1; using Google.Apis.Gmail.v1.Data; using Google.Apis.Http; @@ -60,7 +59,7 @@ public partial class GmailSynchronizerJsonContext : JsonSerializerContext; /// Gmail synchronizer implementation using Gmail History API for efficient incremental sync. /// /// SYNCHRONIZATION STRATEGY: -/// - Initial sync: Downloads up to 1500 messages PER FOLDER with metadata only. +/// - Initial sync: Downloads up to 15c00 messages PER FOLDER with metadata only. /// Uses a global HashSet to track downloaded message IDs, avoiding duplicate downloads /// when messages have multiple labels. Each folder gets its full quota of messages. /// - Incremental sync: Uses ONLY History API to get changes since last sync. @@ -1668,32 +1667,29 @@ public class GmailSynchronizer : WinoSynchronizer bundle.NativeRequest.Service); - for (int i = 0; i < bundleCount; i++) + foreach (var requestGroup in requestGroups) { - var bundle = batchedBundles.ElementAt(i); + var batchedBundles = requestGroup.Batch((int)MaximumAllowedBatchRequestSize); - var nativeBatchRequest = new BatchRequest(_gmailService); - - var bundleRequestCount = bundle.Count(); - - var bundleTasks = new List(); - - for (int k = 0; k < bundleRequestCount; k++) + foreach (var bundle in batchedBundles) { - var requestBundle = bundle.ElementAt(k); - // UI changes are already applied above before batching. + var nativeBatchRequest = new BatchRequest(requestGroup.Key); + var bundleTasks = new List(); - nativeBatchRequest.Queue(requestBundle.NativeRequest, (content, error, index, message) - => bundleTasks.Add(ProcessSingleNativeRequestResponseAsync(requestBundle, error, message, cancellationToken))); + foreach (var requestBundle in bundle) + { + // UI changes are already applied above before batching. + nativeBatchRequest.Queue(requestBundle.NativeRequest, (content, error, index, message) + => bundleTasks.Add(ProcessSingleNativeRequestResponseAsync(requestBundle, error, message, cancellationToken))); + } + + await nativeBatchRequest.ExecuteAsync(cancellationToken).ConfigureAwait(false); + await Task.WhenAll(bundleTasks).ConfigureAwait(false); } - - await nativeBatchRequest.ExecuteAsync(cancellationToken).ConfigureAwait(false); - - await Task.WhenAll(bundleTasks); } }