fix: add job limits for thumbnails to prevent out of memory errors (2)

This commit is contained in:
Louis Dalibard 2024-06-10 21:56:24 +02:00
parent 76f1dcf83e
commit ccaa514080
2 changed files with 3 additions and 3 deletions

View File

@ -1,6 +1,6 @@
{
"host": ":3125",
"thumbnailjoblimit": "5",
"thumbnailjoblimit": 5,
"servedirs": {
"leech": "/home/ontake/Dev/go/leech"
}

View File

@ -5,6 +5,7 @@ import (
"image"
"image/color"
"image/png"
"leech/config"
"os"
"path/filepath"
"slices"
@ -27,7 +28,6 @@ var thumbnailSize = 24
var thumbnailCache = map[string][]byte{}
var thumbnailCacheMutex = &sync.RWMutex{}
var jobLimit = 5
var memLimiterMutex = &sync.RWMutex{}
var jobCounter = 0
var checkAgain = make(chan bool, 5)
@ -39,7 +39,7 @@ func IsSupportedFileType(completePath string) bool {
func WaitForAvailable() {
memLimiterMutex.RLock()
for jobLimit == jobCounter {
for config.Config.ThumbnailJobLimit == jobCounter {
memLimiterMutex.RUnlock()
<-checkAgain
memLimiterMutex.RLock()