Skip to content

Commit

Permalink
remove goembed, use attachment read conditionally in bulk docs
Browse files Browse the repository at this point in the history
  • Loading branch information
torcolvin committed Jul 23, 2024
1 parent fd19b07 commit 6a647e0
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 32 deletions.
14 changes: 0 additions & 14 deletions db/raw_doc_with_inline_sync.json

This file was deleted.

23 changes: 19 additions & 4 deletions db/util_testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ package db

import (
"context"
_ "embed"
"errors"
"fmt"
"sync/atomic"
Expand All @@ -27,9 +26,6 @@ import (
"github.com/stretchr/testify/require"
)

//go:embed raw_doc_with_inline_sync.json
var TestRawDocWithSyncMeta string

// WaitForPrimaryIndexEmpty waits for #primary to be empty.
// Workaround SG #3570 by doing a polling loop until the star channel query returns 0 results.
func WaitForPrimaryIndexEmpty(ctx context.Context, store base.N1QLStore) error {
Expand Down Expand Up @@ -772,3 +768,22 @@ func DefaultMutateInOpts() *sgbucket.MutateInOptions {
MacroExpansion: macroExpandSpec(base.SyncXattrName),
}
}

func RawDocWithInlineSyncData(_ testing.TB) string {
return `
{
"_sync": {
"rev": "1-ca9ad22802b66f662ff171f226211d5c",
"sequence": 1,
"recent_sequences": [1],
"history": {
"revs": ["1-ca9ad22802b66f662ff171f226211d5c"],
"parents": [-1],
"channels": [null]
},
"cas": "",
"time_saved": "2017-11-29T12:46:13.456631-08:00"
}
}
`
}
2 changes: 1 addition & 1 deletion rest/audit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ func TestAuditDocumentCreateUpdateEvents(t *testing.T) {
{
name: "import doc with inline sync meta",
auditableCode: func(t testing.TB, docID string, docVersion DocVersion) {
_, err := rt.GetSingleDataStore().Add(docID, 0, []byte(db.TestRawDocWithSyncMeta))
_, err := rt.GetSingleDataStore().Add(docID, 0, []byte(db.RawDocWithInlineSyncData(t)))
require.NoError(t, err)
// this may get picked up by auto import or on demand import
_, _ = rt.GetDoc(docID)
Expand Down
24 changes: 13 additions & 11 deletions rest/bulk_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,17 +458,19 @@ func (h *handler) handleBulkGet() error {
base.AuditFieldDocID: docid,
base.AuditFieldDocVersion: revid,
})
if atts, ok := body[db.BodyAttachments]; ok && atts != nil {
attsMap, ok := atts.(db.AttachmentsMeta)
if !ok {
base.WarnfCtx(h.ctx(), "Unexpected format of attachments in the body %+v", atts)
}
for attachment := range attsMap {
base.Audit(h.ctx(), base.AuditIDAttachmentRead, base.AuditFields{
base.AuditFieldDocID: docid,
base.AuditFieldDocVersion: revid,
base.AuditFieldAttachmentID: attachment,
})
if includeAttachments {
if atts, ok := body[db.BodyAttachments]; ok && atts != nil {
attsMap, ok := atts.(db.AttachmentsMeta)
if !ok {
base.WarnfCtx(h.ctx(), "Unexpected format of attachments in the body %+v", atts)
}
for attachment := range attsMap {
base.Audit(h.ctx(), base.AuditIDAttachmentRead, base.AuditFields{
base.AuditFieldDocID: docid,
base.AuditFieldDocVersion: revid,
base.AuditFieldAttachmentID: attachment,
})
}
}
}
h.db.DbStats.Database().NumDocReadsRest.Add(1)
Expand Down
4 changes: 2 additions & 2 deletions rest/importtest/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ func TestFeedBasedMigrateWithExpiry(t *testing.T) {
// Create via the SDK with sync metadata intact
expirySeconds := time.Second * 30
testExpiry := uint32(time.Now().Add(expirySeconds).Unix())
bodyString := db.TestRawDocWithSyncMeta
bodyString := db.RawDocWithInlineSyncData(t)
_, err := dataStore.Add(key, testExpiry, []byte(bodyString))
assert.NoError(t, err, "Error writing doc w/ expiry")

Expand Down Expand Up @@ -1343,7 +1343,7 @@ func TestOnDemandMigrateWithExpiry(t *testing.T) {
// Create via the SDK with sync metadata intact
expirySeconds := time.Second * 30
syncMetaExpiry := time.Now().Add(expirySeconds)
bodyString := db.TestRawDocWithSyncMeta
bodyString := db.RawDocWithInlineSyncData(t)
_, err := dataStore.Add(key, uint32(syncMetaExpiry.Unix()), []byte(bodyString))
assert.NoError(t, err, "Error writing doc w/ expiry")

Expand Down

0 comments on commit 6a647e0

Please sign in to comment.