Problem Statement
As a developer, my requirements are to insert a list of events in the Google Calendar with a single call.
Why Batch?
As mentioned here, it helps to reduce the network overheads and increases performance.
Current Scenario
Using the googleapis package, I can only perform a single insert operation as shown in the below snippet :
var eventResponse = await _calendarApi.events
.insert(event, calendarId, sendUpdates: 'all');
From a development perspective, it's not an efficient approach to call this method multiple times.
Also, it would be a bad idea to create an array of the insert method wrapped in Future and use Future.wait() to wait for all the insertion calls to be executed, see below snippet.
Future<List<Event> insertEvents(List<Event> events) async {
var _calendarApi = CalendarApi(_authClient);
List<Future<Event>> _futureEvents = [];
for (int i = 0; i < events.length; i++) {
_futureEvents.add(_calendarApi.events.insert(events[i], calendarId));
}
var _eventResponse =
await Future.wait(_futureEvents).catchError((e) => print(e));
return _eventResponse;
}
As per the official Google Blog, there's no way to perform a batch operation in dart.
Does anyone know a better optimistic solution for this problem?