(channelName string, historyEntry ChannelSetEntry)
| 996 | } |
| 997 | |
| 998 | func (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 |
| 1000 | // whether we need to prune them. |
| 1001 | // As we iterate over the existing channels we will keep track of the oldest and second oldest entries along with |
| 1002 | // their location in the slice. If we need to then prune we can 'merge' the oldest and second oldest and remove |
| 1003 | // the oldest. |
| 1004 | |
| 1005 | var oldestEntryStartSeq uint64 = math.MaxUint64 |
| 1006 | var secondOldestEntryStartSeq uint64 = math.MaxUint64 |
| 1007 | |
| 1008 | oldestEntryIdx := -1 |
| 1009 | secondOldestEntryIdx := -1 |
| 1010 | |
| 1011 | entryCount := 0 |
| 1012 | |
| 1013 | for entryIdx, entry := range doc.ChannelSetHistory { |
| 1014 | if entry.Name == channelName { |
| 1015 | entryCount++ |
| 1016 | |
| 1017 | if entry.Start < oldestEntryStartSeq { |
| 1018 | secondOldestEntryStartSeq = oldestEntryStartSeq |
| 1019 | oldestEntryStartSeq = entry.Start |
| 1020 | |
| 1021 | secondOldestEntryIdx = oldestEntryIdx |
| 1022 | oldestEntryIdx = entryIdx |
| 1023 | continue |
| 1024 | } |
| 1025 | |
| 1026 | if entry.Start < secondOldestEntryStartSeq { |
| 1027 | secondOldestEntryStartSeq = entry.Start |
| 1028 | secondOldestEntryIdx = entryIdx |
| 1029 | } |
| 1030 | } |
| 1031 | } |
| 1032 | |
| 1033 | if entryCount >= DocumentHistoryMaxEntriesPerChannel { |
| 1034 | doc.ChannelSetHistory[secondOldestEntryIdx].Start = oldestEntryStartSeq |
| 1035 | doc.ChannelSetHistory[secondOldestEntryIdx].Compacted = true |
| 1036 | doc.ChannelSetHistory = append(doc.ChannelSetHistory[:oldestEntryIdx], doc.ChannelSetHistory[oldestEntryIdx+1:]...) |
| 1037 | } |
| 1038 | |
| 1039 | doc.ChannelSetHistory = append(doc.ChannelSetHistory, historyEntry) |
| 1040 | } |
| 1041 | |
| 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) |
no outgoing calls
no test coverage detected