Add method timings with conditional logging

- Add timing measurements to key methods
- Only log when duration exceeds 1 second
This commit is contained in:
pascal
2025-11-03 11:52:44 +01:00
parent a2313a5ba4
commit 9eb2faef7f
4 changed files with 25 additions and 0 deletions

View File

@@ -1,5 +1,12 @@
package util
import (
"context"
"time"
log "github.com/sirupsen/logrus"
)
// Difference returns the elements in `a` that aren't in `b`.
func Difference(a, b []string) []string {
mb := make(map[string]struct{}, len(b))
@@ -50,3 +57,13 @@ func contains[T comparableObject[T]](slice []T, element T) bool {
}
return false
}
func TimeTrack(ctx context.Context, name string) func() {
start := time.Now()
return func() {
elapsed := time.Since(start)
if elapsed > time.Second {
log.WithContext(ctx).Infof("Slow Call: [%s] took %s", name, elapsed)
}
}
}