@@ -15,7 +15,6 @@ import (
15
15
"fmt"
16
16
"math"
17
17
"strconv"
18
- "sync"
19
18
20
19
"github.com/couchbase/sync_gateway/base"
21
20
)
@@ -64,10 +63,6 @@ func (tree RevTree) MarshalJSON() ([]byte, error) {
64
63
}
65
64
revIndexes := map [string ]int {"" : - 1 }
66
65
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
-
71
66
i := 0
72
67
for _ , info := range tree {
73
68
revIndexes [info .ID ] = i
@@ -88,20 +83,12 @@ func (tree RevTree) MarshalJSON() ([]byte, error) {
88
83
}
89
84
}
90
85
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
95
87
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 )
104
90
}
91
+ rep .ChannelsMap [strconv .FormatInt (int64 (i ), 10 )] = info .Channels
105
92
}
106
93
107
94
if info .Deleted {
@@ -422,6 +409,7 @@ func (tree RevTree) addRevision(docid string, info RevInfo) error {
422
409
if ! ok {
423
410
return fmt .Errorf ("doc: %v, RevTree addRevision for rev %q, parent id %q is missing" , docid , revid , p )
424
411
}
412
+ parent .Channels = nil
425
413
}
426
414
tree [revid ] = & info
427
415
return nil
0 commit comments