Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions server/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1595,8 +1595,8 @@ const docTemplate = `{
"type": "integer"
},
"preloadCache": {
"description": "in percent",
"type": "integer"
"description": "in percent, rounded to hundredths",
"type": "number"
},
"readerReadAHead": {
"description": "in percent, 5%-100%, [...S__X__E...] [S-E] not clean",
Expand Down
6 changes: 3 additions & 3 deletions server/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1588,8 +1588,8 @@
"type": "integer"
},
"preloadCache": {
"description": "in percent",
"type": "integer"
"description": "in percent, rounded to hundredths",
"type": "number"
},
"readerReadAHead": {
"description": "in percent, 5%-100%, [...S__X__E...] [S-E] not clean",
Expand Down Expand Up @@ -1941,4 +1941,4 @@
"description": "OpenAPI",
"url": "https://swagger.io/resources/open-api/"
}
}
}
4 changes: 2 additions & 2 deletions server/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ definitions:
peersListenPort:
type: integer
preloadCache:
description: in percent
type: integer
description: in percent, rounded to hundredths
type: number
readerReadAHead:
description: in percent, 5%-100%, [...S__X__E...] [S-E] not clean
type: integer
Expand Down
8 changes: 5 additions & 3 deletions server/settings/btsets.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"io"
"io/fs"
"math"
"path/filepath"
"strings"

Expand All @@ -25,9 +26,9 @@ type TMDBConfig struct {

type BTSets struct {
// Cache
CacheSize int64 // in byte, def 64 MB
ReaderReadAHead int // in percent, 5%-100%, [...S__X__E...] [S-E] not clean
PreloadCache int // in percent
CacheSize int64 // in byte, def 64 MB
ReaderReadAHead int // in percent, 5%-100%, [...S__X__E...] [S-E] not clean
PreloadCache float64 // in percent, rounded to hundredths

// Disk
UseDisk bool
Expand Down Expand Up @@ -128,6 +129,7 @@ func SetBTSets(sets *BTSets) {
if sets.PreloadCache > 100 {
sets.PreloadCache = 100
}
sets.PreloadCache = math.Round(sets.PreloadCache*100) / 100

if sets.TorrentsSavePath == "" {
sets.UseDisk = false
Expand Down
2 changes: 1 addition & 1 deletion server/tgbot/admin_preset.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func applyPresetKV(s *settings.BTSets, args []string, uid int64) (bool, string)
ok = true
}
case "preload":
if v := parseInt(val); v >= 0 && v <= 100 {
if v, valid := parseFloat(val); valid && v >= 0 && v <= 100 {
s.PreloadCache = v
ok = true
}
Expand Down
13 changes: 10 additions & 3 deletions server/tgbot/admin_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"strconv"
"strings"

tele "gopkg.in/telebot.v4"
Expand Down Expand Up @@ -57,13 +58,13 @@ func sendSettingsMenuText(c tele.Context, uid int64, page string) string {
case "2":
msg += " — " + tr(uid, "settings_page2")
msg += "\n\n"
msg += fmt.Sprintf("💾 %s: %d MB · Preload %d%% · ReadAhead %d%%\n", tr(uid, "settings_limits_cache"), s.CacheSize/(1024*1024), s.PreloadCache, s.ReaderReadAHead)
msg += fmt.Sprintf("💾 %s: %d MB · Preload %.2f%% · ReadAhead %d%%\n", tr(uid, "settings_limits_cache"), s.CacheSize/(1024*1024), s.PreloadCache, s.ReaderReadAHead)
msg += fmt.Sprintf("🔌 %s: %d · Port %s · Timeout %ds\n", tr(uid, "settings_limits_connections"), s.ConnectionsLimit, portStr(s.PeersListenPort), s.TorrentDisconnectTimeout)
msg += fmt.Sprintf("⬇️ %s: Down %s · Up %s · Retr %s\n", tr(uid, "settings_limits_speed"), rateStr(s.DownloadRateLimit), rateStr(s.UploadRateLimit), retrackersStr(s.RetrackersMode))
case "2a":
msg += " — " + tr(uid, "settings_page2") + " · " + tr(uid, "settings_limits_cache")
msg += "\n\n"
msg += fmt.Sprintf("Cache %d MB · Preload %d%% · ReadAhead %d%%", s.CacheSize/(1024*1024), s.PreloadCache, s.ReaderReadAHead)
msg += fmt.Sprintf("Cache %d MB · Preload %.2f%% · ReadAhead %d%%", s.CacheSize/(1024*1024), s.PreloadCache, s.ReaderReadAHead)
case "2b":
msg += " — " + tr(uid, "settings_page2") + " · " + tr(uid, "settings_limits_connections")
msg += "\n\n"
Expand Down Expand Up @@ -577,7 +578,7 @@ func settingsCallback(c tele.Context, action string) error {
sets.CacheSize = int64(v) * 1024 * 1024
}
case "preload":
if v := parseInt(value); v >= 0 && v <= 100 {
if v, ok := parseFloat(value); ok && v >= 0 && v <= 100 {
sets.PreloadCache = v
}
case "readahead":
Expand Down Expand Up @@ -651,3 +652,9 @@ func parseInt(s string) int {
}
return n
}

func parseFloat(s string) (float64, bool) {
s = strings.TrimSuffix(strings.TrimSpace(s), "%")
v, err := strconv.ParseFloat(strings.ReplaceAll(s, ",", "."), 64)
return v, err == nil
}
2 changes: 2 additions & 0 deletions web/src/components/Settings/PrimarySettingsComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ export default function PrimarySettingsComponent({
sliderMax={100}
inputMin={0}
inputMax={100}
step={0.01}
onBlurCallback={value => setPreloadCachePercentage(Math.round(value * 100) / 100)}
/>
</div>

Expand Down