diff --git a/internal/handlers/home.go b/internal/handlers/home.go index f6b54e4..d047915 100644 --- a/internal/handlers/home.go +++ b/internal/handlers/home.go @@ -26,6 +26,7 @@ type RootResponse struct { Infuse string `json:"infuse"` Logs string `json:"logs"` UserInfo *realdebrid.User `json:"user_info"` // Replace UserInfoType with the actual type + LibrarySize int `json:"library_size"` // Number of torrents in the library MemAlloc uint64 `json:"mem_alloc"` // Memory allocation in MB TotalAlloc uint64 `json:"total_alloc"` // Total memory allocated in MB Sys uint64 `json:"sys"` // System memory in MB @@ -47,20 +48,23 @@ func (zr *Handlers) handleHome(resp http.ResponseWriter, req *http.Request) { var mem runtime.MemStats runtime.ReadMemStats(&mem) + allTorrents, _ := zr.torMgr.DirectoryMap.Get(config.ALL_TORRENTS) + response := RootResponse{ - Version: version.GetVersion(), - BuiltAt: version.GetBuiltAt(), - GitCommit: version.GetGitCommit(), - Html: fmt.Sprintf("//%s/http/", req.Host), - Dav: fmt.Sprintf("//%s/dav/", req.Host), - Infuse: fmt.Sprintf("//%s/infuse/", req.Host), - Logs: fmt.Sprintf("//%s/logs/", req.Host), - UserInfo: userInfo, - MemAlloc: bToMb(mem.Alloc), - TotalAlloc: bToMb(mem.TotalAlloc), - Sys: bToMb(mem.Sys), - NumGC: mem.NumGC, - PID: os.Getpid(), + Version: version.GetVersion(), + BuiltAt: version.GetBuiltAt(), + GitCommit: version.GetGitCommit(), + Html: fmt.Sprintf("//%s/http/", req.Host), + Dav: fmt.Sprintf("//%s/dav/", req.Host), + Infuse: fmt.Sprintf("//%s/infuse/", req.Host), + Logs: fmt.Sprintf("//%s/logs/", req.Host), + UserInfo: userInfo, + LibrarySize: allTorrents.Count(), + MemAlloc: bToMb(mem.Alloc), + TotalAlloc: bToMb(mem.TotalAlloc), + Sys: bToMb(mem.Sys), + NumGC: mem.NumGC, + PID: os.Getpid(), Sponsor: SponsorResponse{ Patreon: "https://www.patreon.com/debridmediamanager", Github: "https://github.com/sponsors/debridmediamanager", @@ -103,6 +107,10 @@ func (zr *Handlers) handleHome(resp http.ResponseWriter, req *http.Request) { Logs %s + + Library Size + %d items + Memory Allocation %d MB @@ -162,7 +170,7 @@ func (zr *Handlers) handleHome(resp http.ResponseWriter, req *http.Request) { %s - Config + Config Version %s @@ -298,6 +306,7 @@ func (zr *Handlers) handleHome(resp http.ResponseWriter, req *http.Request) { response.Infuse, response.Logs, response.Logs, + response.LibrarySize, response.MemAlloc, response.TotalAlloc, response.Sys, diff --git a/internal/torrent/refresh.go b/internal/torrent/refresh.go index a6367c3..0d50a4b 100644 --- a/internal/torrent/refresh.go +++ b/internal/torrent/refresh.go @@ -156,6 +156,14 @@ func (t *TorrentManager) refreshTorrents() []string { }) }) + t.workerPool.Submit(func() { + allTorrents.IterCb(func(accessKey string, torrent *Torrent) { + if torrent.UnassignedLinks.Cardinality() > 0 { + t.assignLinks(torrent) + } + }) + }) + return updatedPaths.ToSlice() } diff --git a/internal/torrent/repair.go b/internal/torrent/repair.go index e6f0052..0b8b3fb 100644 --- a/internal/torrent/repair.go +++ b/internal/torrent/repair.go @@ -164,10 +164,6 @@ func (t *TorrentManager) Repair(torrent *Torrent, wg *sync.WaitGroup) { func (t *TorrentManager) repair(torrent *Torrent) { t.repairLog.Infof("Started repair process for torrent %s (ids=%v)", t.GetKey(torrent), torrent.DownloadedIDs.ToSlice()) - if torrent.UnassignedLinks.Cardinality() > 0 && !t.assignLinks(torrent) { - return - } - // check for other broken files torrent.SelectedFiles.IterCb(func(_ string, file *File) { if !file.State.Is("ok_file") { diff --git a/pkg/realdebrid/api.go b/pkg/realdebrid/api.go index 694dd9a..379a981 100644 --- a/pkg/realdebrid/api.go +++ b/pkg/realdebrid/api.go @@ -366,12 +366,12 @@ func (rd *RealDebrid) GetDownloads() []Download { // reset allDownloads allDownloads := []Download{} page := 1 - limit := 100 + limit := 250 // compute ceiling of totalCount / limit maxPages := (totalCount + limit - 1) / limit rd.log.Debugf("Total downloads count is %d", totalCount) - maxParallelThreads := 8 + maxParallelThreads := 4 if maxPages < maxParallelThreads { maxParallelThreads = maxPages }