Add new configs
This commit is contained in:
@@ -21,21 +21,21 @@ type TorrentManager struct {
|
||||
checksum string
|
||||
}
|
||||
|
||||
func (handler *TorrentManager) refreshTorrents() {
|
||||
func (t *TorrentManager) refreshTorrents() {
|
||||
log.Println("Starting periodic refresh")
|
||||
for {
|
||||
<-time.After(15 * time.Second)
|
||||
checksum := handler.getChecksum()
|
||||
if checksum == handler.checksum {
|
||||
<-time.After(time.Duration(t.config.GetRefreshEverySeconds()) * time.Second)
|
||||
checksum := t.getChecksum()
|
||||
if checksum == t.checksum {
|
||||
continue
|
||||
}
|
||||
handler.checksum = checksum
|
||||
handler.torrents = handler.getAll()
|
||||
for _, torrent := range handler.torrents {
|
||||
t.checksum = checksum
|
||||
t.torrents = t.getAll()
|
||||
for _, torrent := range t.torrents {
|
||||
go func(id string) {
|
||||
handler.workerPool <- true
|
||||
handler.getInfo(id)
|
||||
<-handler.workerPool
|
||||
t.workerPool <- true
|
||||
t.getInfo(id)
|
||||
<-t.workerPool
|
||||
time.Sleep(1 * time.Second) // sleep for 1 second to avoid rate limiting
|
||||
}(torrent.ID)
|
||||
}
|
||||
@@ -48,7 +48,7 @@ func (handler *TorrentManager) refreshTorrents() {
|
||||
func NewTorrentManager(config config.ConfigInterface) *TorrentManager {
|
||||
handler := &TorrentManager{
|
||||
token: config.GetToken(),
|
||||
workerPool: make(chan bool, 10),
|
||||
workerPool: make(chan bool, config.GetNumOfWorkers()),
|
||||
config: config,
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ func (t *TorrentManager) RefreshInfo(torrentID string) {
|
||||
if err == nil {
|
||||
modTime := fileInfo.ModTime()
|
||||
// If the file was modified less than an hour ago, don't refresh
|
||||
if time.Since(modTime) < time.Hour {
|
||||
if time.Since(modTime) < time.Duration(t.config.GetCacheTimeHours())*time.Hour {
|
||||
return
|
||||
}
|
||||
err = os.Remove(filePath)
|
||||
@@ -195,7 +195,7 @@ func (t *TorrentManager) getInfo(torrentID string) *Torrent {
|
||||
var wg sync.WaitGroup
|
||||
|
||||
// Limit concurrency
|
||||
sem := make(chan struct{}, 10) // e.g., 10 concurrent requests
|
||||
sem := make(chan struct{}, t.config.GetNumOfWorkers())
|
||||
|
||||
for _, link := range info.Links {
|
||||
wg.Add(1)
|
||||
|
||||
Reference in New Issue
Block a user