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

Method Mutable1xBody

db/revision_cache_interface.go:302–356  ·  view source on GitHub ↗

Mutable1xBody returns a copy of the given document revision as a 1.x style body (with special properties) Callers are free to modify this body without affecting the document revision.

(ctx context.Context, db *DatabaseCollectionWithUser, requestedHistory Revisions, attachmentsSince []string, showExp bool, showCV bool)

Source from the content-addressed store, hash-verified

300// Mutable1xBody returns a copy of the given document revision as a 1.x style body (with special properties)
301// Callers are free to modify this body without affecting the document revision.
302func (rev *DocumentRevision) Mutable1xBody(ctx context.Context, db *DatabaseCollectionWithUser, requestedHistory Revisions, attachmentsSince []string, showExp bool, showCV bool) (b Body, err error) {
303 b, err = rev.Body()
304 if err != nil {
305 return nil, err
306 }
307 if b == nil {
308 return nil, base.RedactErrorf("null doc body for docID: %s revID: %s", base.UD(rev.DocID), base.UD(rev.RevID))
309 }
310
311 b[BodyId] = rev.DocID
312 b[BodyRev] = rev.RevID
313
314 // Add revision metadata:
315 if requestedHistory != nil {
316 b[BodyRevisions] = requestedHistory
317 }
318
319 if showExp && rev.Expiry != nil && !rev.Expiry.IsZero() {
320 b[BodyExpiry] = rev.Expiry.Format(time.RFC3339)
321 }
322
323 if showCV && rev.CV != nil && !rev.CV.IsEmpty() {
324 b[BodyCV] = rev.CV.String()
325 }
326
327 if rev.Deleted {
328 b[BodyDeleted] = true
329 }
330
331 // Add attachment data if requested:
332 if attachmentsSince != nil {
333 if len(rev.Attachments) > 0 {
334 minRevpos := 1
335 if len(attachmentsSince) > 0 {
336 ancestor := rev.History.findAncestor(attachmentsSince)
337 if ancestor != "" {
338 minRevpos, _ = ParseRevID(ctx, ancestor)
339 minRevpos++
340 }
341 }
342 bodyAtts, err := db.loadAttachmentsData(rev.Attachments, minRevpos, rev.DocID)
343 if err != nil {
344 return nil, err
345 }
346 DeleteAttachmentVersion(bodyAtts)
347 b[BodyAttachments] = bodyAtts
348 }
349 } else if rev.Attachments != nil {
350 // Stamp attachment metadata back into the body
351 DeleteAttachmentVersion(rev.Attachments)
352 b[BodyAttachments] = rev.Attachments
353 }
354
355 return b, nil
356}
357
358// As1xBytes returns a byte slice representing the 1.x style body, containing special properties (i.e. _id, _rev, _attachments, etc.)
359func (rev *DocumentRevision) As1xBytes(ctx context.Context, db *DatabaseCollectionWithUser, requestedHistory Revisions, attachmentsSince []string, showExp bool) (b []byte, err error) {

Callers 2

Calls 9

BodyMethod · 0.95
RedactErrorfFunction · 0.92
UDFunction · 0.92
ParseRevIDFunction · 0.85
DeleteAttachmentVersionFunction · 0.85
findAncestorMethod · 0.80
loadAttachmentsDataMethod · 0.80
StringMethod · 0.65
IsEmptyMethod · 0.45

Tested by 1