Skip to content

Commit 6b1e9b0

Browse files
committed
changes based on pr comments
- fixed the test case for non sgwrite - refactored code around the spec
1 parent a5b726a commit 6b1e9b0

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

db/crud.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,13 +295,13 @@ func (c *DatabaseCollection) CompactDocChannelHistory(ctx context.Context, docid
295295

296296
// build macro expansion for sync data. This will avoid the update to xattrs causing an extra import event (i.e. sync cas will be == to doc cas)
297297
opts := &sgbucket.MutateInOptions{}
298-
spec := []sgbucket.MacroExpansionSpec{}
299-
// Only update _sync.cas if the pre-compaction doc had already been imported by SGW
298+
// Only update _sync.cas and _mou.cas if the pre-compaction doc had already been imported by SGW
300299
if isSgWrite {
301-
spec = append(spec, sgbucket.NewMacroExpansionSpec(XattrMouCasPath(), sgbucket.MacroCas))
302-
spec = append(spec, sgbucket.NewMacroExpansionSpec(xattrCasPath(base.SyncXattrName), sgbucket.MacroCas))
300+
opts.MacroExpansion = []sgbucket.MacroExpansionSpec{
301+
sgbucket.NewMacroExpansionSpec(XattrMouCasPath(), sgbucket.MacroCas),
302+
sgbucket.NewMacroExpansionSpec(xattrCasPath(base.SyncXattrName), sgbucket.MacroCas),
303+
}
303304
}
304-
opts.MacroExpansion = spec
305305
opts.PreserveExpiry = true // if doc has expiry, we should preserve this
306306

307307
updatedXattr := map[string][]byte{

rest/api_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4179,12 +4179,14 @@ func TestCompactNonImportedDocWithAutoImport(t *testing.T) {
41794179
assert.Equal(t, []string{"test_channel"}, compactedChannels)
41804180

41814181
// Step 9: Verify compaction succeeded and history was removed
4182-
syncData, err := collection.GetDocSyncData(ctx, nonImportedDocID)
4182+
require.NoError(t, err)
4183+
syncData, _, err := collection.GetDocSyncDataNoImport(ctx, nonImportedDocID, db.DocUnmarshalSync)
41834184
require.NoError(t, err)
41844185
// History should be compacted
41854186
assert.Less(t, len(syncData.ChannelSetHistory), len(syncDataBefore.ChannelSetHistory))
41864187
// CV must be updated by the import triggered during compaction
4187-
assert.NotEqual(t, cvBeforeCompaction, syncData.CVOrRevTreeID(), "cv should be updated after compaction import")
4188+
// This assertion should be changed after CBG-5397
4189+
assert.Equal(t, cvBeforeCompaction, syncData.CVOrRevTreeID(), "cv should be updated after compaction import")
41884190

41894191
// Step 10: Verify document is still accessible and intact
41904192
docFromBucket, _, err := rt.GetSingleDataStore().GetRaw(ctx, nonImportedDocID)

0 commit comments

Comments
 (0)