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

Method getRevision

db/crud.go:691–726  ·  view source on GitHub ↗

Gets a revision of a document. If it's obsolete it will be loaded from the database if possible. inline "_attachments" properties in the body will be extracted and returned separately if present (pre-2.5 metadata, or backup revisions)

(ctx context.Context, doc *Document, revid string)

Source from the content-addressed store, hash-verified

689// Gets a revision of a document. If it's obsolete it will be loaded from the database if possible.
690// inline "_attachments" properties in the body will be extracted and returned separately if present (pre-2.5 metadata, or backup revisions)
691func (c *DatabaseCollection) getRevision(ctx context.Context, doc *Document, revid string) (bodyBytes []byte, attachments AttachmentsMeta, channels base.Set, err error) {
692 bodyBytes = doc.getRevisionBodyJSON(ctx, revid, c.RevisionBodyLoader)
693
694 // No inline body, so look for separate doc:
695 if bodyBytes == nil {
696 if !doc.History.contains(revid) {
697 return nil, nil, nil, ErrMissing
698 }
699
700 bodyBytes, channels, _, err = c.getOldRevisionJSON(ctx, doc.ID, revid)
701 if err != nil || bodyBytes == nil {
702 return nil, nil, nil, err
703 }
704 }
705
706 if channels == nil {
707 // ignore ok value - we don't care if this is a leaf or not, if we have the data to get channels we'll use it
708 channels, _ = doc.channelsForRevTreeID(revid)
709 }
710
711 // optimistically grab the doc body and to store as a pre-unmarshalled version, as well as anticipating no inline attachments.
712 if doc.GetRevTreeID() == revid {
713 attachments = doc.Attachments()
714 }
715
716 // handle backup revision inline attachments, or pre-2.5 meta
717 if inlineAtts, cleanBodyBytes, _, err := extractInlineAttachments(bodyBytes); err != nil {
718 return nil, nil, nil, err
719 } else if len(inlineAtts) > 0 {
720 // we found some inline attachments, so merge them with attachments, and update the bodies
721 attachments = mergeAttachments(inlineAtts, attachments)
722 bodyBytes = cleanBodyBytes
723 }
724
725 return bodyBytes, attachments, channels, nil
726}
727
728// mergeAttachments copies the attachmentsB map, and merges attachmentsA into it. If both maps are nil, return nil.
729// Conflicting attachment names fall back to a revpos comparison - highest wins. If equivalent, attachment from attachmentsB wins.

Callers

nothing calls this directly

Calls 8

getOldRevisionJSONMethod · 0.95
extractInlineAttachmentsFunction · 0.85
mergeAttachmentsFunction · 0.85
getRevisionBodyJSONMethod · 0.80
containsMethod · 0.80
channelsForRevTreeIDMethod · 0.80
AttachmentsMethod · 0.80
GetRevTreeIDMethod · 0.45

Tested by

no test coverage detected