( ctx context.Context, docExists bool, doc *Document, allowImport bool, previousDocSequenceIn uint64, unusedSequences []uint64, callback updateAndReturnDocCallback, expiry *uint32, docUpdateEvent DocUpdateType, )
| 2535 | } |
| 2536 | |
| 2537 | func (col *DatabaseCollectionWithUser) documentUpdateFunc( |
| 2538 | ctx context.Context, |
| 2539 | docExists bool, |
| 2540 | doc *Document, |
| 2541 | allowImport bool, |
| 2542 | previousDocSequenceIn uint64, |
| 2543 | unusedSequences []uint64, |
| 2544 | callback updateAndReturnDocCallback, |
| 2545 | expiry *uint32, |
| 2546 | docUpdateEvent DocUpdateType, |
| 2547 | ) ( |
| 2548 | retSyncFuncExpiry *uint32, |
| 2549 | retNewRevID string, |
| 2550 | retStoredDoc *Document, |
| 2551 | retOldBodyJSON string, |
| 2552 | retUnusedSequences []uint64, |
| 2553 | changedAccessPrincipals []string, |
| 2554 | changedRoleAccessUsers []string, |
| 2555 | createNewRevIDSkipped bool, |
| 2556 | revokedChannelsRequiringExpansion []string, |
| 2557 | err error) { |
| 2558 | |
| 2559 | err = validateExistingDoc(doc, allowImport, docExists) |
| 2560 | if err != nil { |
| 2561 | return |
| 2562 | } |
| 2563 | |
| 2564 | // grab the current channels so that we're able to use them when stamping the backup revision later |
| 2565 | // we lose channel information for non-leaf revisions in the RevTree when updated, so we take a copy now. |
| 2566 | oldChannels := doc.getCurrentChannels() |
| 2567 | |
| 2568 | // compute mouMatch before the callback modifies doc.MetadataOnlyUpdate |
| 2569 | mouMatch := false |
| 2570 | if doc.MetadataOnlyUpdate != nil && doc.MetadataOnlyUpdate.CAS() == doc.Cas { |
| 2571 | mouMatch = doc.MetadataOnlyUpdate.CAS() == doc.Cas |
| 2572 | base.DebugfCtx(ctx, base.KeyVV, "updateDoc(%q): _mou:%+v Metadata-only update match:%t", base.UD(doc.ID), doc.MetadataOnlyUpdate, mouMatch) |
| 2573 | } else { |
| 2574 | base.DebugfCtx(ctx, base.KeyVV, "updateDoc(%q): has no _mou", base.UD(doc.ID)) |
| 2575 | } |
| 2576 | // Invoke the callback to update the document and with a new revision body to be used by the Sync Function: |
| 2577 | newDoc, newAttachments, createNewRevIDSkipped, updatedExpiry, err := callback(doc) |
| 2578 | if err != nil { |
| 2579 | return |
| 2580 | } |
| 2581 | |
| 2582 | mutableBody, metaMap, newRevID, err := col.prepareSyncFn(doc, newDoc) |
| 2583 | if err != nil { |
| 2584 | return |
| 2585 | } |
| 2586 | |
| 2587 | prevCurrentRev := doc.GetRevTreeID() |
| 2588 | doc.updateWinningRevAndSetDocFlags(ctx) |
| 2589 | newDocHasAttachments := len(newAttachments) > 0 |
| 2590 | col.storeOldBodyInRevTreeAndUpdateCurrent(ctx, doc, prevCurrentRev, newRevID, newDoc, newDocHasAttachments) |
| 2591 | |
| 2592 | syncExpiry, oldBodyJSON, channelSet, access, roles, err := col.runSyncFn(ctx, doc, mutableBody, metaMap, newRevID) |
| 2593 | if err != nil { |
| 2594 | if col.ForceAPIForbiddenErrors() { |
no test coverage detected