MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / ImportDocRaw

Method ImportDocRaw

db/import.go:42–69  ·  view source on GitHub ↗

Imports a document that was written by someone other than sync gateway, given the existing state of the doc in raw bytes

(ctx context.Context, docid string, value []byte, xattrs map[string][]byte, importOpts importDocOptions, cas uint64)

Source from the content-addressed store, hash-verified

40
41// Imports a document that was written by someone other than sync gateway, given the existing state of the doc in raw bytes
42func (db *DatabaseCollectionWithUser) ImportDocRaw(ctx context.Context, docid string, value []byte, xattrs map[string][]byte, importOpts importDocOptions, cas uint64) (docOut *Document, err error) {
43
44 var body Body
45 if importOpts.isDelete {
46 body = Body{}
47 } else {
48 err := body.Unmarshal(value)
49 if err != nil {
50 db.dbStats().SharedBucketImport().ImportErrorCount.Add(1)
51 base.InfofCtx(ctx, base.KeyImport, "Unmarshal error during importDoc %v", err)
52 return nil, base.HTTPErrorf(http.StatusNotFound, "Error unmarshalling %s: %s", base.UD(docid).Redact(), err)
53 }
54
55 err = validateImportBody(body)
56 if err != nil {
57 return nil, err
58 }
59 delete(body, BodyPurged)
60 }
61
62 existingBucketDoc := &sgbucket.BucketDocument{
63 Body: value,
64 Xattrs: xattrs,
65 Cas: cas,
66 }
67
68 return db.importDoc(ctx, docid, body, importOpts.expiry, importOpts.isDelete, importOpts.revSeqNo, existingBucketDoc, importOpts.mode)
69}
70
71// Import a document, given the existing state of the doc in *document format.
72func (db *DatabaseCollectionWithUser) ImportDoc(ctx context.Context, docid string, existingDoc *Document, importOpts importDocOptions) (docOut *Document, err error) {

Callers 4

OnDemandImportForGetMethod · 0.95
TestImportNullDocRawFunction · 0.80
TestHLVImportFunction · 0.80
ImportFeedEventMethod · 0.80

Calls 10

UnmarshalMethod · 0.95
importDocMethod · 0.95
InfofCtxFunction · 0.92
HTTPErrorfFunction · 0.92
UDFunction · 0.92
validateImportBodyFunction · 0.85
SharedBucketImportMethod · 0.80
dbStatsMethod · 0.80
RedactMethod · 0.65
AddMethod · 0.45

Tested by 2

TestImportNullDocRawFunction · 0.64
TestHLVImportFunction · 0.64