(ctx context.Context, userChangeCount uint64, changeWaiter *ChangeWaiter, isContinuous bool)
| 665 | } |
| 666 | |
| 667 | func (col *DatabaseCollectionWithUser) checkForUserUpdates(ctx context.Context, userChangeCount uint64, changeWaiter *ChangeWaiter, isContinuous bool) (isChanged bool, newCount uint64, changedChannels channels.ChangedKeys, err error) { |
| 668 | |
| 669 | newCount = changeWaiter.CurrentUserCount() |
| 670 | // If not continuous, we force user reload as a workaround for https://github.com/couchbase/sync_gateway/issues/2068. For continuous, #2068 is handled by changedChannels check, and |
| 671 | // we can reload only when there's been a user change notification |
| 672 | if newCount > userChangeCount || !isContinuous { |
| 673 | var previousChannels channels.TimedSet |
| 674 | base.DebugfCtx(ctx, base.KeyChanges, "MultiChangesFeed reloading user %+v", base.UD(col.user)) |
| 675 | |
| 676 | if col.user != nil { |
| 677 | previousChannels, err = col.user.InheritedCollectionChannels(col.ScopeName, col.Name) |
| 678 | if err != nil { |
| 679 | base.WarnfCtx(ctx, "Unable to retrieve inherited channels for user %q: %v", base.UD(col.user.Name()), err) |
| 680 | return false, 0, nil, err |
| 681 | } |
| 682 | previousRoles := col.user.RoleNames() |
| 683 | if err := col.ReloadUser(ctx); err != nil { |
| 684 | base.WarnfCtx(ctx, "Error reloading user %q: %v", base.UD(col.user.Name()), err) |
| 685 | return false, 0, nil, err |
| 686 | } |
| 687 | // check whether channel set has changed |
| 688 | channels, err := col.user.InheritedCollectionChannels(col.ScopeName, col.Name) |
| 689 | if err != nil { |
| 690 | base.WarnfCtx(ctx, "Unable to retrieve inherited channels for user %q: %v", base.UD(col.user.Name()), err) |
| 691 | return false, 0, nil, err |
| 692 | } |
| 693 | changedChannels = channels.CompareKeys(previousChannels) |
| 694 | if len(changedChannels) > 0 { |
| 695 | base.DebugfCtx(ctx, base.KeyChanges, "Modified channel set after user reload: %v", base.UD(changedChannels)) |
| 696 | } |
| 697 | |
| 698 | changedRoles := col.user.RoleNames().CompareKeys(previousRoles) |
| 699 | if len(changedRoles) > 0 { |
| 700 | changeWaiter.RefreshUserKeys(col.User(), col.dbCtx.MetadataKeys) |
| 701 | } |
| 702 | } |
| 703 | return true, newCount, changedChannels, nil |
| 704 | } |
| 705 | return false, userChangeCount, nil, nil |
| 706 | } |
| 707 | |
| 708 | // Returns the (ordered) union of all of the changes made to multiple channels. |
| 709 | func (col *DatabaseCollectionWithUser) SimpleMultiChangesFeed(ctx context.Context, chans base.Set, options ChangesOptions) (<-chan *ChangeEntry, error) { |
no test coverage detected