Forget pushed event ids when another calendar is chosen (Feature 16)
Choosing a calendar other than the stored one now clears every plan day's calendar_event_id and edits each plan that had one (revision raised, synced -> changed) in the same transaction as the choice, so a stored event id is always on the chosen calendar and the next push writes the whole week there. PushEvents now runs the push's record under the same account-lock hold as its event writes, so the chosen calendar cannot change between the writes and the sync bookkeeping; a push that read a plan before the choice is refused by its revision check (ErrPlanChanged). Fixes review finding F-01 on task 5885d2b1-cf06-44ff-abf3-242d7763c3c9. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -85,7 +85,12 @@ type eventTime struct {
|
||||
// ErrNoCalendar, a chosen calendar that was deleted or is no longer
|
||||
// writable is ErrCalendarUnavailable, a grant Google no longer accepts is
|
||||
// ErrReconnect, and any other Google failure is a *CalendarError.
|
||||
func (s *Service) PushEvents(ctx context.Context, events []Event) error {
|
||||
//
|
||||
// Once every event is written, PushEvents returns record(), which the
|
||||
// caller uses to store what it pushed. record runs under the same hold of
|
||||
// the account as the writes, so the chosen calendar cannot change between
|
||||
// them; it is not run when a write fails.
|
||||
func (s *Service) PushEvents(ctx context.Context, events []Event, record func() error) error {
|
||||
if len(events) == 0 {
|
||||
return errors.New("gcal: no events to push")
|
||||
}
|
||||
@@ -113,7 +118,7 @@ func (s *Service) PushEvents(ctx context.Context, events []Event) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return record()
|
||||
}
|
||||
|
||||
// writeEvent inserts e at base, the chosen calendar's events collection,
|
||||
|
||||
Reference in New Issue
Block a user