Skip to content

Commit 2d2b42e

Browse files
authored
CBG-4797: make GetCV mirror GetRev and add request for history to it (#7673)
1 parent 5f25273 commit 2d2b42e

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

db/blip_handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,7 @@ func (bh *blipHandler) processRev(rq *blip.Message, stats *processRevStats) (err
11531153
if parseErr != nil {
11541154
return base.HTTPErrorf(http.StatusUnprocessableEntity, "Unable to parse version for delta source for doc %s, error: %v", base.UD(docID), err)
11551155
}
1156-
deltaSrcRev, err = bh.collection.GetCV(bh.loggingCtx, docID, &deltaSrcVersion)
1156+
deltaSrcRev, err = bh.collection.GetCV(bh.loggingCtx, docID, &deltaSrcVersion, false)
11571157
} else {
11581158
deltaSrcRev, err = bh.collection.GetRev(bh.loggingCtx, docID, deltaSrcRevID, false, nil)
11591159
}

db/blip_sync_context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ func (bsc *BlipSyncContext) sendRevision(ctx context.Context, sender *blip.Sende
687687
if vrsErr != nil {
688688
return vrsErr
689689
}
690-
docRev, originalErr = handleChangesResponseCollection.GetCV(bsc.loggingCtx, docID, &version)
690+
docRev, originalErr = handleChangesResponseCollection.GetCV(bsc.loggingCtx, docID, &version, true)
691691
}
692692

693693
// set if we find an alternative revision to send in the event the originally requested rev is unavailable

db/crud.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ func (db *DatabaseCollectionWithUser) documentRevisionForRequest(ctx context.Con
437437
return revision, nil
438438
}
439439

440-
func (db *DatabaseCollectionWithUser) GetCV(ctx context.Context, docid string, cv *Version) (revision DocumentRevision, err error) {
440+
func (db *DatabaseCollectionWithUser) GetCV(ctx context.Context, docid string, cv *Version, revTreeHistory bool) (revision DocumentRevision, err error) {
441441
if cv != nil {
442442
revision, err = db.revisionCache.GetWithCV(ctx, docid, cv, RevCacheOmitDelta)
443443
} else {
@@ -446,8 +446,12 @@ func (db *DatabaseCollectionWithUser) GetCV(ctx context.Context, docid string, c
446446
if err != nil {
447447
return DocumentRevision{}, err
448448
}
449+
maxHistory := 0
450+
if revTreeHistory {
451+
maxHistory = math.MaxInt32
452+
}
449453

450-
return db.documentRevisionForRequest(ctx, docid, revision, nil, cv, 0, nil)
454+
return db.documentRevisionForRequest(ctx, docid, revision, nil, cv, maxHistory, nil)
451455
}
452456

453457
// GetDelta attempts to return the delta between fromRevId and toRevId. If the delta can't be generated,

db/crud_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1959,7 +1959,7 @@ func TestGetCVWithDocResidentInCache(t *testing.T) {
19591959
vrs := doc.HLV.Version
19601960
src := doc.HLV.SourceID
19611961
sv := &Version{Value: vrs, SourceID: src}
1962-
revision, err := collection.GetCV(ctx, docID, sv)
1962+
revision, err := collection.GetCV(ctx, docID, sv, false)
19631963
require.NoError(t, err)
19641964
if testCase.access {
19651965
assert.Equal(t, rev, revision.RevID)
@@ -2018,7 +2018,7 @@ func TestGetByCVForDocNotResidentInCache(t *testing.T) {
20182018
vrs := doc.HLV.Version
20192019
src := doc.HLV.SourceID
20202020
sv := &Version{Value: vrs, SourceID: src}
2021-
revision, err := collection.GetCV(ctx, doc1ID, sv)
2021+
revision, err := collection.GetCV(ctx, doc1ID, sv, false)
20222022
require.NoError(t, err)
20232023

20242024
// assert the fetched doc is the first doc we added and assert that we did in fact get cache miss
@@ -2072,7 +2072,7 @@ func TestGetCVActivePathway(t *testing.T) {
20722072
revBody := Body{"channels": testCase.docChannels}
20732073
rev, doc, err := collection.Put(ctx, docID, revBody)
20742074
require.NoError(t, err)
2075-
revision, err := collection.GetCV(ctx, docID, nil)
2075+
revision, err := collection.GetCV(ctx, docID, nil, false)
20762076

20772077
if testCase.access == true {
20782078
require.NoError(t, err)

0 commit comments

Comments
 (0)