@@ -1698,7 +1698,6 @@ func (db *DatabaseCollectionWithUser) PutExistingRevWithBody(ctx context.Context
16981698// access map for users, roles, handler errors and sync fn exceptions.
16991699// If syncFn is provided, it will be used instead of the one configured on the database.
17001700func (db * DatabaseCollectionWithUser ) SyncFnDryrun (ctx context.Context , newDoc , oldDoc * Document , syncFn string , errorLogFunc , infoLogFunc func (string )) (* channels.ChannelMapperOutput , error ) {
1701-
17021701 mutableBody , metaMap , _ , err := db .prepareSyncFn (oldDoc , newDoc )
17031702 if err != nil {
17041703 base .InfofCtx (ctx , base .KeyDiagnostic , "Failed to prepare to run sync function: %v" , err )
@@ -1709,32 +1708,30 @@ func (db *DatabaseCollectionWithUser) SyncFnDryrun(ctx context.Context, newDoc,
17091708 if err != nil {
17101709 return nil , err
17111710 }
1712- var output * channels.ChannelMapperOutput
1713- var syncErr error
1714- if syncFn == "" && db .ChannelMapper != nil {
1715- output , err = db .ChannelMapper .MapToChannelsAndAccess (ctx , mutableBody , string (oldDoc ._rawBody ), metaMap , syncOptions )
1716- if err != nil {
1717- return nil , & base.SyncFnDryRunError {Err : err }
1718- }
1719- } else {
1720- if syncFn == "" {
1711+
1712+ // fetch configured sync function if one is not provided
1713+ if syncFn == "" {
1714+ if db .ChannelMapper != nil {
1715+ syncFn = db .ChannelMapper .Function ()
1716+ } else {
17211717 scopeAndCollectionName := db .ScopeAndCollectionName ()
17221718 syncFn = channels .GetDefaultSyncFunction (scopeAndCollectionName .Scope , scopeAndCollectionName .Collection )
17231719 }
1724- jsTimeout := time .Duration (base .DefaultJavascriptTimeoutSecs ) * time .Second
1725- syncRunner , err := channels .NewSyncRunnerWithLogging (ctx , syncFn , jsTimeout , errorLogFunc , infoLogFunc )
1726- if err != nil {
1727- return nil , fmt .Errorf ("failed to create sync runner: %v" , err )
1728- }
1729- jsOutput , err := syncRunner .Call (ctx , mutableBody , string (oldDoc ._rawBody ), metaMap , syncOptions )
1730- if err != nil {
1720+ }
17311721
1732- return nil , & base.SyncFnDryRunError {Err : err }
1733- }
1734- output = jsOutput .(* channels.ChannelMapperOutput )
1722+ // create new sync runner instance for this dry run
1723+ jsTimeout := time .Duration (base .DefaultJavascriptTimeoutSecs ) * time .Second
1724+ syncRunner , err := channels .NewSyncRunnerWithLogging (ctx , syncFn , jsTimeout , errorLogFunc , infoLogFunc )
1725+ if err != nil {
1726+ return nil , fmt .Errorf ("failed to create sync runner: %v" , err )
1727+ }
1728+
1729+ jsOutput , err := syncRunner .Call (ctx , mutableBody , sgbucket .JSONString (oldDoc ._rawBody ), metaMap , syncOptions )
1730+ if err != nil {
1731+ return nil , & base.SyncFnDryRunError {Err : err }
17351732 }
17361733
1737- return output , syncErr
1734+ return jsOutput .( * channels. ChannelMapperOutput ), nil
17381735}
17391736
17401737// revTreeConflictCheck checks for conflicts in the rev tree history and returns the parent revid, currentRevIndex
0 commit comments