Minor changes to image cleanup function and calling

Signed-off-by: Ethan Wellenreiter <ewellenreiter@gmail.com>
This commit is contained in:
Ethan Wellenreiter 2025-05-07 10:27:35 -04:00
parent 780b646d68
commit 6a949ae682

View File

@ -14,7 +14,7 @@ const imgStoreCleanupTime = time.Hour * 12
func NewSQLImageStore(db *sql.DB) *SQLImagesStore {
imgstore := &SQLImagesStore{db}
go imgstore.cleanupDeadImages()
go imgstore.cleanupDeadImages(context.Background(), imgStoreCleanupTime)
return imgstore
}
@ -88,8 +88,8 @@ func (s *SQLImagesStore) ActivateImage(ctx context.Context, id int64) error {
return nil
}
func (s *SQLImagesStore) cleanupDeadImages(ctx context.Context) {
for range time.Tick(imgStoreCleanupTime) {
func (s *SQLImagesStore) cleanupDeadImages(ctx context.Context, period time.Duration) {
for range time.Tick(period) {
query := `DELETE FROM images WHERE added = false AND expiration < $1`
ctx, cancel := context.WithTimeout(ctx, QueryTimeoutDuration)