diff --git a/internal/config/config.go b/internal/config/config.go index 013163ed8..161712904 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -55,7 +55,7 @@ func init() { TotalMem = memory.TotalMemory() // Check available memory if not running in unsafe mode. - if os.Getenv("PHOTOPRISM_UNSAFE") == "" { + if Env(EnvUnsafe) { // Disable features with high memory requirements? LowMem = TotalMem < MinMem } @@ -594,12 +594,18 @@ func (c *Config) WakeupInterval() time.Duration { // Default to 15 minutes if no interval is set. return DefaultWakeupInterval } - } else if c.options.WakeupInterval > MaxWakeupInterval { - // Do not run less than once per day. - return MaxWakeupInterval - } else if c.options.WakeupInterval < MinWakeupInterval { - // Do not run more than once per minute. + } + + // Do not run more than once per minute. + if c.options.WakeupInterval < MinWakeupInterval/time.Second { return MinWakeupInterval + } else if c.options.WakeupInterval < MinWakeupInterval { + c.options.WakeupInterval = c.options.WakeupInterval * time.Second + } + + // Do not run less than once per day. + if c.options.WakeupInterval > MaxWakeupInterval { + return MaxWakeupInterval } return c.options.WakeupInterval diff --git a/internal/config/config_test.go b/internal/config/config_test.go index e9f73c913..e3b857b3d 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -285,6 +285,15 @@ func TestConfig_Workers(t *testing.T) { func TestConfig_WakeupInterval(t *testing.T) { c := NewConfig(CliTestContext()) + i := c.WakeupInterval() + assert.Equal(t, "1h34m9s", c.WakeupInterval().String()) + c.options.WakeupInterval = 45 + assert.Equal(t, "1m0s", c.WakeupInterval().String()) + c.options.WakeupInterval = 0 + assert.Equal(t, "15m0s", c.WakeupInterval().String()) + c.options.WakeupInterval = 150 + assert.Equal(t, "2m30s", c.WakeupInterval().String()) + c.options.WakeupInterval = i assert.Equal(t, "1h34m9s", c.WakeupInterval().String()) } diff --git a/internal/config/env.go b/internal/config/env.go index d59415ead..b8fdd880b 100644 --- a/internal/config/env.go +++ b/internal/config/env.go @@ -9,6 +9,7 @@ import ( // Environment names. const ( + EnvUnsafe = "unsafe" EnvDebug = "debug" EnvTrace = "trace" EnvDemo = "demo" diff --git a/internal/config/global_flags.go b/internal/config/global_flags.go index 90bd9acf5..a75a6d44d 100644 --- a/internal/config/global_flags.go +++ b/internal/config/global_flags.go @@ -64,7 +64,7 @@ var Flags = CliFlags{ Flag: cli.BoolFlag{ Name: "unsafe", Hidden: true, - Usage: "enable unsafe mode", + Usage: "disable safety checks", EnvVar: "PHOTOPRISM_UNSAFE", }}, CliFlag{