Skip to content

Commit 707ce13

Browse files
committed
Skip leaf check when storing for ChannelMap - nil out parent channels on addRevision
1 parent 8ea4063 commit 707ce13

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

db/revtree.go

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"fmt"
1616
"math"
1717
"strconv"
18-
"sync"
1918

2019
"github.com/couchbase/sync_gateway/base"
2120
)
@@ -64,10 +63,6 @@ func (tree RevTree) MarshalJSON() ([]byte, error) {
6463
}
6564
revIndexes := map[string]int{"": -1}
6665

67-
// there's no way to lookup leaves by key without doing a full tree iteration, so we'll just do it once the first time we need it
68-
var leaves map[string]*RevInfo
69-
leavesOnce := sync.Once{}
70-
7166
i := 0
7267
for _, info := range tree {
7368
revIndexes[info.ID] = i
@@ -88,20 +83,12 @@ func (tree RevTree) MarshalJSON() ([]byte, error) {
8883
}
8984
}
9085

91-
// for leaf revisions we'll store channel information
92-
// there's some duplication here for the current rev
93-
// (active channels are stored outside the revtree)
94-
// but special casing this doesn't seem worthwhile
86+
// for non-winning leaf revisions we'll store channel information
9587
if len(info.Channels) > 0 {
96-
leavesOnce.Do(func() {
97-
leaves = tree.Leaves()
98-
})
99-
if _, isLeaf := leaves[info.ID]; isLeaf {
100-
if rep.ChannelsMap == nil {
101-
rep.ChannelsMap = make(map[string]base.Set, 1)
102-
}
103-
rep.ChannelsMap[strconv.FormatInt(int64(i), 10)] = info.Channels
88+
if rep.ChannelsMap == nil {
89+
rep.ChannelsMap = make(map[string]base.Set, 1)
10490
}
91+
rep.ChannelsMap[strconv.FormatInt(int64(i), 10)] = info.Channels
10592
}
10693

10794
if info.Deleted {
@@ -422,6 +409,7 @@ func (tree RevTree) addRevision(docid string, info RevInfo) error {
422409
if !ok {
423410
return fmt.Errorf("doc: %v, RevTree addRevision for rev %q, parent id %q is missing", docid, revid, p)
424411
}
412+
parent.Channels = nil
425413
}
426414
tree[revid] = &info
427415
return nil

0 commit comments

Comments
 (0)