Skip to content

Commit 2d69700

Browse files
authored
CBG-4470: Simplify PutExistingCurrentVersion (#7866)
1 parent 7691406 commit 2d69700

File tree

1 file changed

+1
-15
lines changed

1 file changed

+1
-15
lines changed

db/crud.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,24 +1286,10 @@ func (db *DatabaseCollectionWithUser) Put(ctx context.Context, docid string, bod
12861286
// false and len(RevTreeHistory) > 0 then this means the local version of this doc does not have an HLV so this parameter
12871287
// will be used to check for conflicts.
12881288
func (db *DatabaseCollectionWithUser) PutExistingCurrentVersion(ctx context.Context, opts PutDocOptions) (doc *Document, cv *Version, newRevID string, err error) {
1289-
var matchRev string
1290-
if opts.ExistingDoc != nil {
1291-
doc, unmarshalErr := db.unmarshalDocumentWithXattrs(ctx, opts.NewDoc.ID, opts.ExistingDoc.Body, opts.ExistingDoc.Xattrs, opts.ExistingDoc.Cas, DocUnmarshalRev)
1292-
if unmarshalErr != nil {
1293-
return nil, nil, "", base.HTTPErrorf(http.StatusBadRequest, "Error unmarshaling existing doc")
1294-
}
1295-
matchRev = doc.GetRevTreeID()
1296-
}
1297-
generation, _ := ParseRevID(ctx, matchRev)
1298-
if generation < 0 {
1299-
return nil, nil, "", base.HTTPErrorf(http.StatusBadRequest, "Invalid revision ID")
1300-
}
1301-
generation++ //nolint
13021289

13031290
docUpdateEvent := ExistingVersion
1304-
allowImport := db.UseXattrs()
13051291
updateRevCache := true
1306-
doc, newRevID, err = db.updateAndReturnDoc(ctx, opts.NewDoc.ID, allowImport, &opts.NewDoc.DocExpiry, nil, docUpdateEvent, opts.ExistingDoc, false, updateRevCache, func(doc *Document) (resultDoc *Document, resultAttachmentData updatedAttachments, createNewRevIDSkipped bool, updatedExpiry *uint32, resultErr error) {
1292+
doc, newRevID, err = db.updateAndReturnDoc(ctx, opts.NewDoc.ID, true, &opts.NewDoc.DocExpiry, nil, docUpdateEvent, opts.ExistingDoc, false, updateRevCache, func(doc *Document) (resultDoc *Document, resultAttachmentData updatedAttachments, createNewRevIDSkipped bool, updatedExpiry *uint32, resultErr error) {
13071293
// (Be careful: this block can be invoked multiple times if there are races!)
13081294

13091295
var isSgWrite bool

0 commit comments

Comments
 (0)