Delete expired attachments based on mod time instead of DB entry to avoid races

This commit is contained in:
Philipp Heckel 2022-07-08 10:00:04 -04:00
parent 3e53d8a2c7
commit 10a9aca2a1
6 changed files with 65 additions and 43 deletions

View file

@ -1116,8 +1116,9 @@ func (s *Server) updateStatsAndPrune() {
log.Debug("Manager: Deleted %d stale visitor(s)", staleVisitors)
// Delete expired attachments
if s.fileCache != nil {
ids, err := s.messageCache.AttachmentsExpired()
if s.fileCache != nil && s.config.AttachmentExpiryDuration > 0 {
olderThan := time.Now().Add(-1 * s.config.AttachmentExpiryDuration)
ids, err := s.fileCache.Expired(olderThan)
if err != nil {
log.Warn("Error retrieving expired attachments: %s", err.Error())
} else if len(ids) > 0 {