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)
| 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) |
| 691 | func (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. |
nothing calls this directly
no test coverage detected