(ctx context.Context, doc *Document, casOut uint64)
| 3010 | } |
| 3011 | |
| 3012 | func (db *DatabaseCollectionWithUser) postWriteUpdateHLV(ctx context.Context, doc *Document, casOut uint64) *Document { |
| 3013 | if doc.HLV == nil { |
| 3014 | return doc |
| 3015 | } |
| 3016 | if doc.HLV.Version == expandMacroCASValueUint64 { |
| 3017 | doc.HLV.Version = casOut |
| 3018 | } |
| 3019 | if doc.HLV.CurrentVersionCAS == expandMacroCASValueUint64 { |
| 3020 | doc.HLV.CurrentVersionCAS = casOut |
| 3021 | } |
| 3022 | doc.SyncData.SetCV(doc.HLV) |
| 3023 | |
| 3024 | // backup new revision to the bucket now we have a doc assigned a CV (post macro expansion) for future deltaSrc purposes |
| 3025 | // we don't need to store revision body backups without delta sync in 4.0, since all clients know how to use the sendReplacementRevs feature |
| 3026 | backupRev := db.deltaSyncEnabled() && db.deltaSyncRevMaxAgeSeconds() != 0 |
| 3027 | if db.UseXattrs() && backupRev { |
| 3028 | var newBodyWithAtts = doc._rawBody |
| 3029 | if len(doc.Attachments()) > 0 { |
| 3030 | var err error |
| 3031 | newBodyWithAtts, err = base.InjectJSONProperties(doc._rawBody, base.KVPair{ |
| 3032 | Key: BodyAttachments, |
| 3033 | Val: doc.Attachments(), |
| 3034 | }) |
| 3035 | if err != nil { |
| 3036 | base.WarnfCtx(ctx, "Unable to marshal new revision body during backupRevisionJSON: doc=%q rev=%q cv=%q err=%v ", base.UD(doc.ID), doc.GetRevTreeID(), doc.HLV.GetCurrentVersionString(), err) |
| 3037 | return doc |
| 3038 | } |
| 3039 | } |
| 3040 | revHash := base.Crc32cHashString([]byte(doc.HLV.GetCurrentVersionString())) |
| 3041 | _ = db.setOldRevisionJSON(ctx, doc.ID, revHash, newBodyWithAtts, doc.IsDeleted(), db.deltaSyncRevMaxAgeSeconds(), doc.getCurrentChannels()) |
| 3042 | // Optionally store a lookup document to find the CV-based revHash by legacy RevTree ID |
| 3043 | if db.storeLegacyRevTreeData() { |
| 3044 | _ = db.setOldRevisionJSONPtr(ctx, doc, db.deltaSyncRevMaxAgeSeconds()) |
| 3045 | } |
| 3046 | } |
| 3047 | return doc |
| 3048 | } |
| 3049 | |
| 3050 | // getAttachmentIDsForLeafRevisions returns a map of attachment docids with values of attachment names. |
| 3051 | func getAttachmentIDsForLeafRevisions(ctx context.Context, db *DatabaseCollectionWithUser, doc *Document, newRevID string) (map[string][]string, error) { |
no test coverage detected