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

Method getCurrentVersion

db/revision_cache_interface.go:496–525  ·  view source on GitHub ↗
(ctx context.Context, doc *Document, cv Version, loadBackup bool)

Source from the content-addressed store, hash-verified

494}
495
496func (c *DatabaseCollection) getCurrentVersion(ctx context.Context, doc *Document, cv Version, loadBackup bool) (bodyBytes []byte, attachments AttachmentsMeta, channels base.Set, deleted bool, err error) {
497 if err = doc.HasCurrentVersion(ctx, cv); err != nil {
498 if !loadBackup {
499 // do not attempt to fetch backup revision by CV unless specified
500 return nil, nil, nil, false, ErrMissing
501 }
502 bodyBytes, channels, deleted, err = c.getOldRevisionJSON(ctx, doc.ID, base.Crc32cHashString([]byte(cv.String())))
503 if err != nil || bodyBytes == nil {
504 return nil, nil, nil, false, err
505 }
506 } else {
507 bodyBytes, err = doc.BodyBytes(ctx)
508 if err != nil {
509 base.WarnfCtx(ctx, "Marshal error when retrieving active current version body: %v", err)
510 return nil, nil, nil, false, err
511 }
512 channels = doc.SyncData.getCurrentChannels()
513 attachments = doc.Attachments()
514 }
515
516 // handle backup revision inline attachments, or pre-2.5 meta
517 if inlineAtts, cleanBodyBytes, _, err := extractInlineAttachments(bodyBytes); err != nil {
518 return nil, nil, nil, false, err
519 } else if len(inlineAtts) > 0 {
520 // we found some inline attachments, so merge them with attachments, and update the bodies
521 attachments = mergeAttachments(inlineAtts, attachments)
522 bodyBytes = cleanBodyBytes
523 }
524 return bodyBytes, attachments, channels, deleted, err
525}

Callers

nothing calls this directly

Calls 10

getOldRevisionJSONMethod · 0.95
Crc32cHashStringFunction · 0.92
WarnfCtxFunction · 0.92
extractInlineAttachmentsFunction · 0.85
mergeAttachmentsFunction · 0.85
HasCurrentVersionMethod · 0.80
getCurrentChannelsMethod · 0.80
AttachmentsMethod · 0.80
StringMethod · 0.65
BodyBytesMethod · 0.45

Tested by

no test coverage detected