mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 05:26:09 +05:00
optimization memory
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
package rutor
|
package rutor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"compress/flate"
|
"compress/flate"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/agnivade/levenshtein"
|
"github.com/agnivade/levenshtein"
|
||||||
@@ -100,24 +99,50 @@ func updateDB() {
|
|||||||
|
|
||||||
func loadDB() {
|
func loadDB() {
|
||||||
log.TLogln("Load rutor db")
|
log.TLogln("Load rutor db")
|
||||||
buf, err := os.ReadFile(filepath.Join(settings.Path, "rutor.ls"))
|
ff, err := os.Open(filepath.Join(settings.Path, "rutor.ls"))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
r := flate.NewReader(bytes.NewReader(buf))
|
defer ff.Close()
|
||||||
buf, err = io.ReadAll(r)
|
r := flate.NewReader(ff)
|
||||||
r.Close()
|
defer r.Close()
|
||||||
if err == nil {
|
var ftorrs []*models.TorrentDetails
|
||||||
var ftors []*models.TorrentDetails
|
dec := json.NewDecoder(r)
|
||||||
err = json.Unmarshal(buf, &ftors)
|
|
||||||
|
_, err := dec.Token()
|
||||||
|
if err != nil {
|
||||||
|
log.TLogln("Error read token rutor db:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var channel = make(chan *models.TorrentDetails, 0)
|
||||||
|
go func() {
|
||||||
|
for torr := range channel {
|
||||||
|
ftorrs = append(ftorrs, torr)
|
||||||
|
}
|
||||||
|
torrs = ftorrs
|
||||||
|
}()
|
||||||
|
|
||||||
|
for dec.More() {
|
||||||
|
var torr *models.TorrentDetails
|
||||||
|
err = dec.Decode(&torr)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
torrs = ftors
|
channel <- torr
|
||||||
log.TLogln("Index rutor db")
|
|
||||||
torrsearch.NewIndex(torrs)
|
|
||||||
} else {
|
} else {
|
||||||
log.TLogln("Error read rutor db:", err)
|
log.TLogln("Error read rutor db:", err)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
log.TLogln("Error read rutor db:", err)
|
|
||||||
}
|
}
|
||||||
|
close(channel)
|
||||||
|
|
||||||
|
log.TLogln("Index rutor db")
|
||||||
|
torrsearch.NewIndex(torrs)
|
||||||
|
|
||||||
|
//err = dec.Decode(&ftorrs)
|
||||||
|
//if err == nil {
|
||||||
|
// torrs = ftorrs
|
||||||
|
// log.TLogln("Index rutor db")
|
||||||
|
// torrsearch.NewIndex(torrs)
|
||||||
|
//} else {
|
||||||
|
// log.TLogln("Error read rutor db:", err)
|
||||||
|
//}
|
||||||
} else {
|
} else {
|
||||||
log.TLogln("Error load rutor db:", err)
|
log.TLogln("Error load rutor db:", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user