Assign links outside repair

This commit is contained in:
Ben Adrian Sarmiento
2024-06-05 10:37:38 +02:00
parent c62cdeace8
commit fa26553933
4 changed files with 33 additions and 20 deletions

View File

@@ -26,6 +26,7 @@ type RootResponse struct {
Infuse string `json:"infuse"` Infuse string `json:"infuse"`
Logs string `json:"logs"` Logs string `json:"logs"`
UserInfo *realdebrid.User `json:"user_info"` // Replace UserInfoType with the actual type 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 MemAlloc uint64 `json:"mem_alloc"` // Memory allocation in MB
TotalAlloc uint64 `json:"total_alloc"` // Total memory allocated in MB TotalAlloc uint64 `json:"total_alloc"` // Total memory allocated in MB
Sys uint64 `json:"sys"` // System memory in MB Sys uint64 `json:"sys"` // System memory in MB
@@ -47,6 +48,8 @@ func (zr *Handlers) handleHome(resp http.ResponseWriter, req *http.Request) {
var mem runtime.MemStats var mem runtime.MemStats
runtime.ReadMemStats(&mem) runtime.ReadMemStats(&mem)
allTorrents, _ := zr.torMgr.DirectoryMap.Get(config.ALL_TORRENTS)
response := RootResponse{ response := RootResponse{
Version: version.GetVersion(), Version: version.GetVersion(),
BuiltAt: version.GetBuiltAt(), BuiltAt: version.GetBuiltAt(),
@@ -56,6 +59,7 @@ func (zr *Handlers) handleHome(resp http.ResponseWriter, req *http.Request) {
Infuse: fmt.Sprintf("//%s/infuse/", req.Host), Infuse: fmt.Sprintf("//%s/infuse/", req.Host),
Logs: fmt.Sprintf("//%s/logs/", req.Host), Logs: fmt.Sprintf("//%s/logs/", req.Host),
UserInfo: userInfo, UserInfo: userInfo,
LibrarySize: allTorrents.Count(),
MemAlloc: bToMb(mem.Alloc), MemAlloc: bToMb(mem.Alloc),
TotalAlloc: bToMb(mem.TotalAlloc), TotalAlloc: bToMb(mem.TotalAlloc),
Sys: bToMb(mem.Sys), Sys: bToMb(mem.Sys),
@@ -103,6 +107,10 @@ func (zr *Handlers) handleHome(resp http.ResponseWriter, req *http.Request) {
<td>Logs</td> <td>Logs</td>
<td colspan="2"><a href="%s">%s</a></td> <td colspan="2"><a href="%s">%s</a></td>
</tr> </tr>
<tr>
<td>Library Size</td>
<td colspan="2">%d items</td>
</tr>
<tr> <tr>
<td>Memory Allocation</td> <td>Memory Allocation</td>
<td colspan="2">%d MB</td> <td colspan="2">%d MB</td>
@@ -162,7 +170,7 @@ func (zr *Handlers) handleHome(resp http.ResponseWriter, req *http.Request) {
<td>%s</td> <td>%s</td>
</tr> </tr>
<tr> <tr>
<td rowspan="23">Config</td> <td rowspan="22">Config</td>
<td>Version</td> <td>Version</td>
<td>%s</td> <td>%s</td>
</tr> </tr>
@@ -298,6 +306,7 @@ func (zr *Handlers) handleHome(resp http.ResponseWriter, req *http.Request) {
response.Infuse, response.Infuse,
response.Logs, response.Logs,
response.Logs, response.Logs,
response.LibrarySize,
response.MemAlloc, response.MemAlloc,
response.TotalAlloc, response.TotalAlloc,
response.Sys, response.Sys,

View File

@@ -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() return updatedPaths.ToSlice()
} }

View File

@@ -164,10 +164,6 @@ func (t *TorrentManager) Repair(torrent *Torrent, wg *sync.WaitGroup) {
func (t *TorrentManager) repair(torrent *Torrent) { func (t *TorrentManager) repair(torrent *Torrent) {
t.repairLog.Infof("Started repair process for torrent %s (ids=%v)", t.GetKey(torrent), torrent.DownloadedIDs.ToSlice()) 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 // check for other broken files
torrent.SelectedFiles.IterCb(func(_ string, file *File) { torrent.SelectedFiles.IterCb(func(_ string, file *File) {
if !file.State.Is("ok_file") { if !file.State.Is("ok_file") {

View File

@@ -366,12 +366,12 @@ func (rd *RealDebrid) GetDownloads() []Download {
// reset allDownloads // reset allDownloads
allDownloads := []Download{} allDownloads := []Download{}
page := 1 page := 1
limit := 100 limit := 250
// compute ceiling of totalCount / limit // compute ceiling of totalCount / limit
maxPages := (totalCount + limit - 1) / limit maxPages := (totalCount + limit - 1) / limit
rd.log.Debugf("Total downloads count is %d", totalCount) rd.log.Debugf("Total downloads count is %d", totalCount)
maxParallelThreads := 8 maxParallelThreads := 4
if maxPages < maxParallelThreads { if maxPages < maxParallelThreads {
maxParallelThreads = maxPages maxParallelThreads = maxPages
} }