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

Method OnDemandImportForGet

db/crud.go:246–273  ·  view source on GitHub ↗

OnDemandImportForGet. Attempts to import the doc based on the provided id, contents and cas. ImportDocRaw does cas retry handling if the document gets updated after the initial retrieval attempt that triggered this.

(ctx context.Context, docid string, doc *Document, rawDoc []byte, xattrs map[string][]byte, cas uint64)

Source from the content-addressed store, hash-verified

244// OnDemandImportForGet. Attempts to import the doc based on the provided id, contents and cas. ImportDocRaw does cas retry handling
245// if the document gets updated after the initial retrieval attempt that triggered this.
246func (c *DatabaseCollection) OnDemandImportForGet(ctx context.Context, docid string, doc *Document, rawDoc []byte, xattrs map[string][]byte, cas uint64) (docOut *Document, err error) {
247 isDelete := rawDoc == nil
248 importDb := DatabaseCollectionWithUser{DatabaseCollection: c, user: nil}
249 var importErr error
250
251 if syncDataErr := doc.validateSyncDataForImport(ctx, c.dbCtx, docid); syncDataErr != nil {
252 return nil, syncDataErr
253 }
254
255 importOpts := importDocOptions{
256 isDelete: isDelete,
257 mode: ImportOnDemand,
258 revSeqNo: doc.RevSeqNo,
259 expiry: nil,
260 }
261
262 docOut, importErr = importDb.ImportDocRaw(ctx, docid, rawDoc, xattrs, importOpts, cas)
263
264 if importErr == base.ErrImportCancelledFilter {
265 // If the import was cancelled due to filter, treat as 404 not imported
266 return nil, base.HTTPErrorf(http.StatusNotFound, "Not imported")
267 } else if importErr != nil {
268 // Treat any other failure to perform an on-demand import as not found
269 base.DebugfCtx(ctx, base.KeyImport, "Unable to import doc %q during on demand import for get - will be treated as not found. Reason: %v", base.UD(docid), importErr)
270 return nil, base.HTTPErrorf(http.StatusNotFound, "Not found")
271 }
272 return docOut, nil
273}
274
275// GetRev returns the revision for the given docID and revOrCV, or the current active revision if revOrCV is empty.
276func (db *DatabaseCollectionWithUser) GetRev(ctx context.Context, docID, revOrCV string, history bool, attachmentsSince []string) (DocumentRevision, error) {

Callers 2

GetDocumentWithRawMethod · 0.95
GetDocSyncDataMethod · 0.95

Calls 5

ImportDocRawMethod · 0.95
HTTPErrorfFunction · 0.92
DebugfCtxFunction · 0.92
UDFunction · 0.92

Tested by

no test coverage detected