Skip to content

Commit

Permalink
do not allocate recordcleaner.Cleaner when not needed (#4232)
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 authored Feb 7, 2025
1 parent d31f1ab commit e8e21bf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
13 changes: 12 additions & 1 deletion internal/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 0 additions & 13 deletions internal/recordcleaner/cleaner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e8e21bf

Please sign in to comment.