28 lines
602 B
Go
28 lines
602 B
Go
|
|
package sqlruntime
|
||
|
|
|
||
|
|
import "time"
|
||
|
|
|
||
|
|
// CloneHookArgs creates a shallow copy for hook consumers to avoid mutation races.
|
||
|
|
func CloneHookArgs(args []interface{}) []interface{} {
|
||
|
|
if len(args) == 0 {
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
copied := make([]interface{}, len(args))
|
||
|
|
copy(copied, args)
|
||
|
|
return copied
|
||
|
|
}
|
||
|
|
|
||
|
|
// ShouldRunAfterHook decides whether after-hook should run.
|
||
|
|
func ShouldRunAfterHook(hasAfterHook bool, slowThreshold, duration time.Duration, err error) bool {
|
||
|
|
if !hasAfterHook {
|
||
|
|
return false
|
||
|
|
}
|
||
|
|
if err != nil {
|
||
|
|
return true
|
||
|
|
}
|
||
|
|
if slowThreshold <= 0 {
|
||
|
|
return true
|
||
|
|
}
|
||
|
|
return duration >= slowThreshold
|
||
|
|
}
|