Skip to content

Commit

Permalink
CBG-4460 Updates based on PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
adamcfraser committed Jan 15, 2025
1 parent c52d11f commit ef9182e
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 11 deletions.
3 changes: 2 additions & 1 deletion db/blip_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,8 @@ func (bh *blipHandler) handleProposeChanges(rq *blip.Message) error {
changeIsVector = strings.Contains(rev, "@")
}
if versionVectorProtocol && changeIsVector {
status, currentRev = bh.collection.CheckProposedVersion(bh.loggingCtx, docID, rev, parentRevID)
proposedVersionStr := ExtractCVFromProposeChangesRev(rev)
status, currentRev = bh.collection.CheckProposedVersion(bh.loggingCtx, docID, proposedVersionStr, parentRevID)
} else {
changesContainLegacyRevs = true
status, currentRev = bh.collection.CheckProposedRev(bh.loggingCtx, docID, rev, parentRevID)
Expand Down
10 changes: 0 additions & 10 deletions db/crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -3213,16 +3213,6 @@ func (db *DatabaseCollectionWithUser) CheckProposedRev(ctx context.Context, doci
// CheckProposedVersion - given DocID and a version in string form, check whether it can be added without conflict.
func (db *DatabaseCollectionWithUser) CheckProposedVersion(ctx context.Context, docid, proposedVersionStr string, previousRev string) (status ProposedRevStatus, currentVersion string) {

// CBG-4460 - Temporarily strip any trailing HLV content from proposedVersionStr
pvDelimiter := strings.Index(proposedVersionStr, ";")
if pvDelimiter > 0 {
proposedVersionStr = proposedVersionStr[:pvDelimiter]
}
mvDelimiter := strings.Index(proposedVersionStr, ",")
if mvDelimiter > 0 {
proposedVersionStr = proposedVersionStr[:mvDelimiter]
}

proposedVersion, err := ParseVersion(proposedVersionStr)
if err != nil {
base.WarnfCtx(ctx, "Couldn't parse proposed version for doc %q / %q: %v", base.UD(docid), proposedVersionStr, err)
Expand Down
14 changes: 14 additions & 0 deletions db/hybrid_logical_vector.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,20 @@ func ExtractHLVFromBlipMessage(versionVectorStr string) (*HybridLogicalVector, [
}
}

// ExtractCVFromProposeChangesRev strips any trailing HLV content from proposeChanges rev property(CBG-4460)
func ExtractCVFromProposeChangesRev(rev string) string {
pvDelimiter := strings.Index(rev, ";")
if pvDelimiter > 0 {
rev = rev[:pvDelimiter]
}
mvDelimiter := strings.Index(rev, ",")
if mvDelimiter > 0 {
rev = rev[:mvDelimiter]
}

return strings.TrimSpace(rev)
}

// parseVectorValues takes an HLV section (cv, pv or mv) in string form and splits into
// source and version pairs. Also returns legacyRev list if legacy revID's are found in the input string.
func parseVectorValues(vectorStr string) (versions []Version, legacyRevList []string, err error) {
Expand Down
58 changes: 58 additions & 0 deletions db/hybrid_logical_vector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,64 @@ func TestExtractHLVFromChangesMessage(t *testing.T) {
}
}

// TestExtractCVFromProposeChangesRev
func TestExtractCVFromProposeChangesRev(t *testing.T) {

var testCases = []struct {
name string
inputRev string
expectedCV string
}{
{
name: "cv only",
inputRev: "1000@abc",
expectedCV: "1000@abc",
},
{
name: "cv trailing whitespace",
inputRev: "1000@abc ",
expectedCV: "1000@abc",
},
{
name: "cv and mv",
inputRev: "1000@abc,900@abc,900@def",
expectedCV: "1000@abc",
},
{
name: "cv and mv trailing whitespace",
inputRev: "1000@abc ,900@abc,900@def",
expectedCV: "1000@abc",
},
{
name: "cv trailing whitespace",
inputRev: "1000@abc ",
expectedCV: "1000@abc",
},
{
name: "cv and pv",
inputRev: "1000@abc;900@def,800@ghi",
expectedCV: "1000@abc",
},
{
name: "cv, mv, pv",
inputRev: "1000@abc,900@abc,900@def;900@def,800@ghi",
expectedCV: "1000@abc",
},
{
name: "cv, mv, pv, creative whitespace",
inputRev: " 1000@abc ,900@abc, 900@def; 900@def,800@ghi ",
expectedCV: "1000@abc",
},
}

for _, test := range testCases {
t.Run(test.name, func(t *testing.T) {
cv := ExtractCVFromProposeChangesRev(test.inputRev)
assert.Equal(t, test.expectedCV, cv)
})
}
}

func BenchmarkExtractHLVFromBlipMessage(b *testing.B) {
for _, bm := range extractHLVFromBlipMsgBMarkCases {
b.Run(bm.name, func(b *testing.B) {
Expand Down

0 comments on commit ef9182e

Please sign in to comment.