This commit is contained in:
binwiederhier
2026-03-22 16:20:45 -04:00
parent a04128520d
commit 4d07897d2d
+5 -5
View File
@@ -34,7 +34,7 @@ type Store struct {
sizes map[string]int64 // File ID -> size, for subtracting on Remove sizes map[string]int64 // File ID -> size, for subtracting on Remove
localIDs func() ([]string, error) // Returns file IDs that should exist locally, used for sync() localIDs func() ([]string, error) // Returns file IDs that should exist locally, used for sync()
closeChan chan struct{} closeChan chan struct{}
mu sync.Mutex // Protects size and sizes mu sync.RWMutex // Protects size and sizes
} }
// NewFileStore creates a new file-system backed attachment cache // NewFileStore creates a new file-system backed attachment cache
@@ -191,15 +191,15 @@ func (c *Store) sync() error {
// Size returns the current total size of all attachments // Size returns the current total size of all attachments
func (c *Store) Size() int64 { func (c *Store) Size() int64 {
c.mu.Lock() c.mu.RLock()
defer c.mu.Unlock() defer c.mu.RUnlock()
return c.size return c.size
} }
// Remaining returns the remaining capacity for attachments // Remaining returns the remaining capacity for attachments
func (c *Store) Remaining() int64 { func (c *Store) Remaining() int64 {
c.mu.Lock() c.mu.RLock()
defer c.mu.Unlock() defer c.mu.RUnlock()
remaining := c.limit - c.size remaining := c.limit - c.size
if remaining < 0 { if remaining < 0 {
return 0 return 0