mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 13:00:52 +08:00
Introduce `WithSkipPersist` to disable persistence during Manager Update/Register calls, preventing write-back loops caused by redundant file writes. Add corresponding tests and integrate with existing file store and conductor logic.
25 lines
710 B
Go
25 lines
710 B
Go
package auth
|
|
|
|
import "context"
|
|
|
|
type skipPersistContextKey struct{}
|
|
|
|
// WithSkipPersist returns a derived context that disables persistence for Manager Update/Register calls.
|
|
// It is intended for code paths that are reacting to file watcher events, where the file on disk is
|
|
// already the source of truth and persisting again would create a write-back loop.
|
|
func WithSkipPersist(ctx context.Context) context.Context {
|
|
if ctx == nil {
|
|
ctx = context.Background()
|
|
}
|
|
return context.WithValue(ctx, skipPersistContextKey{}, true)
|
|
}
|
|
|
|
func shouldSkipPersist(ctx context.Context) bool {
|
|
if ctx == nil {
|
|
return false
|
|
}
|
|
v := ctx.Value(skipPersistContextKey{})
|
|
enabled, ok := v.(bool)
|
|
return ok && enabled
|
|
}
|