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

Method prepareSyncFn

db/crud.go:2283–2309  ·  view source on GitHub ↗
(doc *Document, newDoc *Document)

Source from the content-addressed store, hash-verified

2281}
2282
2283func (db *DatabaseCollectionWithUser) prepareSyncFn(doc *Document, newDoc *Document) (mutableBody Body, metaMap map[string]interface{}, newRevID string, err error) {
2284 // Marshal raw user xattrs for use in Sync Fn. If this fails we can bail out so we should do early as possible.
2285 metaMap, err = doc.GetMetaMap(db.UserXattrKey())
2286 if err != nil {
2287 return
2288 }
2289
2290 mutableBody, err = newDoc.GetDeepMutableBody()
2291 if err != nil {
2292 return
2293 }
2294
2295 err = validateNewBody(mutableBody)
2296 if err != nil {
2297 return
2298 }
2299
2300 newRevID = newDoc.RevID
2301
2302 mutableBody[BodyId] = doc.ID
2303 mutableBody[BodyRev] = newRevID
2304 if newDoc.Deleted {
2305 mutableBody[BodyDeleted] = true
2306 }
2307
2308 return
2309}
2310
2311// Run the sync function on the given document and body. Need to inject the document ID and rev ID temporarily to run
2312// the sync function.

Callers 4

PutMethod · 0.95
SyncFnDryRunMethod · 0.95
documentUpdateFuncMethod · 0.95
CreateDocNoHLVMethod · 0.95

Calls 4

validateNewBodyFunction · 0.85
GetMetaMapMethod · 0.80
UserXattrKeyMethod · 0.80
GetDeepMutableBodyMethod · 0.80

Tested by

no test coverage detected