persistModifiedRevisionBodies writes new non-inline revisions to the bucket. Should be invoked BEFORE the document is successfully committed.
(datastore sgbucket.DataStore)
| 859 | // persistModifiedRevisionBodies writes new non-inline revisions to the bucket. |
| 860 | // Should be invoked BEFORE the document is successfully committed. |
| 861 | func (doc *Document) persistModifiedRevisionBodies(datastore sgbucket.DataStore) error { |
| 862 | |
| 863 | for _, revID := range doc.addedRevisionBodies { |
| 864 | // if this rev is also in the delete set, skip add/delete |
| 865 | _, ok := doc.removedRevisionBodyKeys[revID] |
| 866 | if ok { |
| 867 | delete(doc.removedRevisionBodyKeys, revID) |
| 868 | continue |
| 869 | } |
| 870 | |
| 871 | revInfo, err := doc.History.getInfo(revID) |
| 872 | if revInfo == nil || err != nil { |
| 873 | return err |
| 874 | } |
| 875 | if revInfo.BodyKey == "" || len(revInfo.Body) == 0 { |
| 876 | return base.RedactErrorf("Missing key or body for revision during external persistence. doc: %s rev:%s key: %s len(body): %d", base.UD(doc.ID), revID, base.UD(revInfo.BodyKey), len(revInfo.Body)) |
| 877 | } |
| 878 | |
| 879 | // If addRaw indicates that the doc already exists, can ignore. Another writer already persisted this rev backup. |
| 880 | addErr := doc.persistRevisionBody(datastore, revInfo.BodyKey, revInfo.Body) |
| 881 | if addErr != nil { |
| 882 | return err |
| 883 | } |
| 884 | } |
| 885 | |
| 886 | doc.addedRevisionBodies = []string{} |
| 887 | return nil |
| 888 | } |
| 889 | |
| 890 | // deleteRemovedRevisionBodies deletes obsolete non-inline revisions from the bucket. |
| 891 | // Should be invoked AFTER the document is successfully committed. |
no test coverage detected