Fix mutexes in the cacher

This commit is contained in:
2026-02-12 02:28:23 +03:00
parent 2fbc12d770
commit f22111aa43
5 changed files with 36 additions and 11 deletions

View File

@@ -18,6 +18,8 @@ func (c *Cacher) GetFileDTO(sourcePath string) (*dto.CacheItem, error) {
return nil, fmt.Errorf("%w: %w (%w)", ErrCacher, ErrFailedToGetSourceFile, err)
}
c.app.Logger().WithField("item", item).Debug("Retrieved cache item")
return models.CacheItemModelToDTO(item), nil
}
@@ -32,8 +34,8 @@ func (c *Cacher) getFile(sourcePath string) (*models.CacheItem, error) {
cacheKey := fmt.Sprintf("%x", hash)
cacheFilePath := filepath.Join(c.cacheDir, cacheKey+".m4a")
c.cacheMutex.Lock()
defer c.cacheMutex.Unlock()
c.itemsMutex.Lock()
defer c.itemsMutex.Unlock()
// Check if file information exists in cache
if item, ok := c.items[cacheKey]; ok {
@@ -92,7 +94,7 @@ func (c *Cacher) getFile(sourcePath string) (*models.CacheItem, error) {
c.updateCachedStat(sourcePath, size)
// TODO: run cleanup on inotify events.
c.cleanup()
// c.cleanup()
return item, nil
}