Fix 100% CPU when EDIT_TIME=0 in image cleanup
When EditDuration is zero or negative, cleanupTTL becomes zero, causing time.After(0) to fire immediately in a tight loop. Block on ctx.Done() instead when edit duration is disabled. Fixes #1991
This commit is contained in:
@@ -154,6 +154,12 @@ func (s *Service) ExtractNonProxiedPictures(commentHTML string) (ids []string) {
|
||||
|
||||
// Cleanup runs periodic cleanup with 1.5*ServiceParams.EditDuration. Blocking loop, should be called inside of goroutine by consumer
|
||||
func (s *Service) Cleanup(ctx context.Context) {
|
||||
if s.EditDuration <= 0 {
|
||||
log.Printf("[INFO] pictures cleanup disabled, edit duration is %v", s.EditDuration)
|
||||
<-ctx.Done()
|
||||
return
|
||||
}
|
||||
|
||||
cleanupTTL := s.EditDuration * 15 / 10 // cleanup images older than 1.5 * EditDuration
|
||||
log.Printf("[INFO] start pictures cleanup, staging ttl=%v", cleanupTTL)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user