Skip to content

Commit

Permalink
Don't cache recurring instances into googleExceptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
phw198 committed Jan 4, 2025
1 parent c1bc2e6 commit 83e6d2c
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions src/OutlookGoogleCalendarSync/Google/GoogleRecurrence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,12 @@ public static void SeparateGoogleExceptions(List<Event> allEvents) {
}

/// <summary>
/// Get occurrence that originally started on a particular date
/// Search cached exceptions for occurrence that originally started on a particular date
/// </summary>
/// <param name="recurringEventId">The recurring series to search within</param>
/// <param name="originalInstanceDate">The date to search for</param>
/// <returns></returns>
private static Event getGoogleInstance(String recurringEventId, System.DateTime originalInstanceDate) {
public static Event GetGoogleInstance(String recurringEventId, System.DateTime originalInstanceDate) {
return googleExceptions.FirstOrDefault(g => g.RecurringEventId == recurringEventId && g.OriginalStartTime.SafeDateTime().Date == originalInstanceDate);
}

Expand Down Expand Up @@ -307,29 +307,27 @@ private static Event getGoogleInstance(Microsoft.Office.Interop.Outlook.Exceptio
}
}
if (dirtyCache) {
log.Debug("Google exception cache not being used. Retrieving all recurring instances afresh...");
log.Debug("Google exception cache not being used. Retrieving all recurring exceptions afresh...");
//Remove dirty items
googleExceptions.RemoveAll(ev => ev.RecurringEventId == gRecurringEventID);
} else {
foreach (Event gExcp in googleExceptions) {
if (gExcp.RecurringEventId == gRecurringEventID) {
if (((oIsDeleted == Outlook.Recurrence.DeletionState.NotDeleted || (oIsDeleted == Outlook.Recurrence.DeletionState.Deleted && !oExcp.Deleted)) /* Weirdness when exception is cancelled by organiser but not yet deleted/accepted by recipient */
&& oExcp.OriginalDate == gExcp.OriginalStartTime.SafeDateTime()
) ||
(oIsDeleted == Outlook.Recurrence.DeletionState.Deleted &&
oExcp.OriginalDate == gExcp.OriginalStartTime.SafeDateTime().Date
)) {
return gExcp;
}
Google.Calendar.Instance.GetCalendarEntriesInRange(gRecurringEventID);
}
foreach (Event gExcp in googleExceptions) {
if (gExcp.RecurringEventId == gRecurringEventID) {
if (((oIsDeleted == Outlook.Recurrence.DeletionState.NotDeleted || (oIsDeleted == Outlook.Recurrence.DeletionState.Deleted && !oExcp.Deleted)) /* Weirdness when exception is cancelled by organiser but not yet deleted/accepted by recipient */
&& oExcp.OriginalDate == gExcp.OriginalStartTime.SafeDateTime()
) ||
(oIsDeleted == Outlook.Recurrence.DeletionState.Deleted &&
oExcp.OriginalDate == gExcp.OriginalStartTime.SafeDateTime().Date
)) {
return gExcp;
}
}
log.Debug("Google exception event is not cached. Retrieving all recurring instances...");
}
log.Debug("Google exception event is not cached. Retrieving all recurring instances...");
List<Event> gInstances = Ogcs.Google.Calendar.Instance.GetCalendarEntriesInRecurrence(gRecurringEventID);
if (gInstances == null) return null;

//Add any new exceptions to local cache
googleExceptions = googleExceptions.Union(gInstances.Where(ev => !String.IsNullOrEmpty(ev.RecurringEventId))).ToList();
foreach (Event gInst in gInstances) {
if (gInst.RecurringEventId == gRecurringEventID) {
if (((oIsDeleted == Outlook.Recurrence.DeletionState.NotDeleted || (oIsDeleted == Outlook.Recurrence.DeletionState.Deleted && !oExcp.Deleted)) /* Weirdness when exception is cancelled by organiser but not yet deleted/accepted by recipient */
Expand Down Expand Up @@ -569,7 +567,7 @@ public static void UpdateGoogleExceptions(AppointmentItem ai, Event ev, Boolean
} else if (oIsDeleted == Outlook.Recurrence.DeletionState.Deleted && gExcp.Status != "cancelled") {
System.DateTime movedToStartDate = gExcp.Start.SafeDateTime().Date;
log.Fine("Checking if we have another Google instance that /is/ cancelled on " + movedToStartDate.ToString("dd-MMM-yyyy") + " that this one has been moved to.");
Event duplicate = getGoogleInstance(gExcp.RecurringEventId, movedToStartDate);
Event duplicate = GetGoogleInstance(gExcp.RecurringEventId, movedToStartDate);
DialogResult dr = DialogResult.Yes;
String summary = Outlook.Calendar.GetEventSummary(ai, out String anonSummary);
if (duplicate?.Status == "cancelled") {
Expand Down

0 comments on commit 83e6d2c

Please sign in to comment.