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

Method updateChannelHistory

db/document.go:953–996  ·  view source on GitHub ↗

CHANNELS & ACCESS:

(channelName string, seq uint64, addition bool)

Source from the content-addressed store, hash-verified

951// ////// CHANNELS & ACCESS:
952
953func (doc *Document) updateChannelHistory(channelName string, seq uint64, addition bool) {
954 // Check if we already have an entry for this channel
955 for idx, historyEntry := range doc.ChannelSet {
956 if historyEntry.Name == channelName {
957 // If we are here there is an existing entry for this channel
958 // If addition we need to:
959 // - Move existing history entry to old channels
960 // - Remove existing entry from current channels
961 // - Add new entry with start seq
962 // If removal / not addition then we can simply add the end seq
963 if addition {
964 // If there is no end for the current entry we're in an unexpected state as you can't have an addition
965 // of the same channel twice without a removal in between. If we're somehow in this state we don't know
966 // when the removal happened so best we can do is skip this addition work and keep the existing start.
967 if doc.ChannelSet[idx].End == 0 {
968 return
969 }
970 doc.addToChannelSetHistory(channelName, historyEntry)
971 doc.ChannelSet[idx] = ChannelSetEntry{Name: channelName, Start: seq}
972 } else {
973 doc.ChannelSet[idx].End = seq
974 }
975 return
976 }
977 }
978
979 // If we get to this point there is no existing entry
980 // If addition we can just simply add it
981 // If its a removal / not addition then its a legacy document. Start seq is 1 because we don't know when legacy
982 // channels were added
983 if addition {
984 doc.ChannelSet = append(doc.ChannelSet, ChannelSetEntry{
985 Name: channelName,
986 Start: seq,
987 })
988 } else {
989 doc.ChannelSet = append(doc.ChannelSet, ChannelSetEntry{
990 Name: channelName,
991 Start: 1,
992 End: seq,
993 })
994 }
995
996}
997
998func (doc *Document) addToChannelSetHistory(channelName string, historyEntry ChannelSetEntry) {
999 // Before adding the entry we need to verify the number of items in the document channel history to check

Callers 1

updateChannelsMethod · 0.95

Calls 1

Tested by

no test coverage detected