MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / updateChannels

Method updateChannels

db/document.go:1044–1083  ·  view source on GitHub ↗

Updates the Channels property of a document object with current & past channels. Returns the set of channels that have changed (document joined or left in this revision)

(ctx context.Context, newChannels base.Set)

Source from the content-addressed store, hash-verified

1042// Updates the Channels property of a document object with current & past channels.
1043// Returns the set of channels that have changed (document joined or left in this revision)
1044func (doc *Document) updateChannels(ctx context.Context, newChannels base.Set) (changedChannels base.Set, revokedChannelsRequiringExpansion []string, err error) {
1045 var changed []string
1046 oldChannels := doc.Channels
1047 if oldChannels == nil {
1048 oldChannels = channels.ChannelMap{}
1049 doc.Channels = oldChannels
1050 } else {
1051 // Mark every no-longer-current channel as unsubscribed:
1052 curSequence := doc.Sequence
1053 curRevAndVersion := doc.RevAndVersion
1054 for channel, removal := range oldChannels {
1055 if removal == nil && !newChannels.Contains(channel) {
1056 oldChannels[channel] = &channels.ChannelRemoval{
1057 Seq: curSequence,
1058 Rev: curRevAndVersion,
1059 Deleted: doc.hasFlag(channels.Deleted)}
1060 doc.updateChannelHistory(channel, curSequence, false)
1061 changed = append(changed, channel)
1062 // If the current version requires macro expansion, new removal in channel map will also require macro expansion
1063 if doc.HLV != nil && doc.HLV.Version == expandMacroCASValueUint64 {
1064 revokedChannelsRequiringExpansion = append(revokedChannelsRequiringExpansion, channel)
1065 }
1066 }
1067 }
1068 }
1069
1070 // Mark every current channel as subscribed:
1071 for channel := range newChannels {
1072 if value, exists := oldChannels[channel]; value != nil || !exists {
1073 oldChannels[channel] = nil
1074 changed = append(changed, channel)
1075 doc.updateChannelHistory(channel, doc.Sequence, true)
1076 }
1077 }
1078 if changed != nil {
1079 base.InfofCtx(ctx, base.KeyCRUD, "\tDoc %q / %q in channels %q", base.UD(doc.ID), doc.GetRevTreeID(), base.UD(newChannels))
1080 changedChannels, err = channels.SetFromArray(changed, channels.KeepStar)
1081 }
1082 return
1083}
1084
1085// Determine whether the specified revision was a channel removal, based on doc.Channels. If so, construct the standard document body for a
1086// removal notification (_removed=true)

Callers 3

GetDocumentMethod · 0.80
getResyncedDocumentMethod · 0.80
documentUpdateFuncMethod · 0.80

Calls 7

hasFlagMethod · 0.95
updateChannelHistoryMethod · 0.95
InfofCtxFunction · 0.92
UDFunction · 0.92
SetFromArrayFunction · 0.92
ContainsMethod · 0.65
GetRevTreeIDMethod · 0.45

Tested by 1

GetDocumentMethod · 0.64