Optimizations
This commit is contained in:
@@ -94,6 +94,22 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, r
|
||||
|
||||
t.workerPool.Submit(func() {
|
||||
defer wg.Done()
|
||||
|
||||
// load *.zurgtorrent files
|
||||
allTorrents, _ := t.DirectoryMap.Get(INT_ALL)
|
||||
t.getTorrentFiles("data").Each(func(filePath string) bool {
|
||||
torrent := t.readTorrentFromFile(filePath)
|
||||
if torrent != nil {
|
||||
accessKey := t.GetKey(torrent)
|
||||
allTorrents.Set(accessKey, torrent)
|
||||
t.assignDirectory(torrent, func(directory string) {
|
||||
listing, _ := t.DirectoryMap.Get(directory)
|
||||
listing.Set(accessKey, torrent)
|
||||
})
|
||||
}
|
||||
return false
|
||||
})
|
||||
|
||||
t.refreshTorrents()
|
||||
})
|
||||
t.workerPool.Submit(func() {
|
||||
@@ -253,8 +269,8 @@ func (t *TorrentManager) readTorrentFromFile(filePath string) *Torrent {
|
||||
return torrent
|
||||
}
|
||||
|
||||
func (t *TorrentManager) deleteTorrentFile(hash string) {
|
||||
filePath := "data/" + hash + ".zurgtorrent"
|
||||
func (t *TorrentManager) deleteTorrentFile(filename string) {
|
||||
filePath := "data/" + filename + ".zurgtorrent"
|
||||
_ = os.Remove(filePath)
|
||||
}
|
||||
|
||||
@@ -263,7 +279,7 @@ func (t *TorrentManager) deleteTorrentFile(hash string) {
|
||||
/// info functions
|
||||
|
||||
func (t *TorrentManager) getInfoFiles() mapset.Set[string] {
|
||||
files, err := filepath.Glob("data/*.zurginfo")
|
||||
files, err := filepath.Glob("data/info/*.zurginfo")
|
||||
if err != nil {
|
||||
t.log.Warnf("Cannot get files in data directory: %v", err)
|
||||
return nil
|
||||
@@ -272,7 +288,7 @@ func (t *TorrentManager) getInfoFiles() mapset.Set[string] {
|
||||
}
|
||||
|
||||
func (t *TorrentManager) writeInfoToFile(info *realdebrid.TorrentInfo) {
|
||||
filePath := "data/" + info.ID + ".zurginfo"
|
||||
filePath := "data/info/" + info.ID + ".zurginfo"
|
||||
file, err := os.Create(filePath)
|
||||
if err != nil {
|
||||
t.log.Warnf("Cannot create info file %s: %v", filePath, err)
|
||||
@@ -295,7 +311,7 @@ func (t *TorrentManager) writeInfoToFile(info *realdebrid.TorrentInfo) {
|
||||
}
|
||||
|
||||
func (t *TorrentManager) readInfoFromFile(torrentID string) *realdebrid.TorrentInfo {
|
||||
filePath := "data/" + torrentID + ".zurginfo"
|
||||
filePath := "data/info/" + torrentID + ".zurginfo"
|
||||
file, err := os.Open(filePath)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
@@ -316,7 +332,7 @@ func (t *TorrentManager) readInfoFromFile(torrentID string) *realdebrid.TorrentI
|
||||
}
|
||||
|
||||
func (t *TorrentManager) deleteInfoFile(torrentID string) {
|
||||
filePath := "data/" + torrentID + ".zurginfo"
|
||||
filePath := "data/info/" + torrentID + ".zurginfo"
|
||||
_ = os.Remove(filePath)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user