do not allocate recordcleaner.Cleaner when not needed (#4232)

This commit is contained in:
Alessandro Ros
2025-02-07 17:11:20 +01:00
committed by GitHub
parent d31f1ab882
commit e8e21bfa42
2 changed files with 12 additions and 14 deletions
+12 -1
View File
@@ -52,6 +52,15 @@ var cli struct {
Confpath string `arg:"" default:""`
}
func atLeastOneRecordDeleteAfter(pathConfs map[string]*conf.Path) bool {
for _, e := range pathConfs {
if e.RecordDeleteAfter != 0 {
return true
}
}
return false
}
// Core is an instance of MediaMTX.
type Core struct {
ctx context.Context
@@ -306,7 +315,8 @@ func (p *Core) createResources(initial bool) error {
p.pprof = i
}
if p.recordCleaner == nil {
if p.recordCleaner == nil &&
atLeastOneRecordDeleteAfter(p.conf.Paths) {
p.recordCleaner = &recordcleaner.Cleaner{
PathConfs: p.conf.Paths,
Parent: p,
@@ -674,6 +684,7 @@ func (p *Core) closeResources(newConf *conf.Conf, calledByAPI bool) {
closeLogger
closeRecorderCleaner := newConf == nil ||
atLeastOneRecordDeleteAfter(newConf.Paths) != atLeastOneRecordDeleteAfter(p.conf.Paths) ||
closeLogger
if !closeRecorderCleaner && !reflect.DeepEqual(newConf.Paths, p.conf.Paths) {
p.recordCleaner.ReloadPathConfs(newConf.Paths)
-13
View File
@@ -75,20 +75,7 @@ func (c *Cleaner) run() {
}
}
func (c *Cleaner) atLeastOneRecordDeleteAfter() bool {
for _, e := range c.PathConfs {
if e.RecordDeleteAfter != 0 {
return true
}
}
return false
}
func (c *Cleaner) cleanInterval() time.Duration {
if !c.atLeastOneRecordDeleteAfter() {
return 365 * 24 * time.Hour
}
interval := 30 * 60 * time.Second
for _, e := range c.PathConfs {