mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 13:36:09 +05:00
change pieces prior set
This commit is contained in:
@@ -165,7 +165,7 @@ func (c *Cache) cleanPieces() {
|
||||
|
||||
remPieces := c.getRemPieces()
|
||||
if c.filled > c.capacity {
|
||||
rems := (c.filled - c.capacity) / c.pieceLength
|
||||
rems := (c.filled-c.capacity)/c.pieceLength + 1
|
||||
for _, p := range remPieces {
|
||||
c.removePiece(p)
|
||||
rems--
|
||||
@@ -192,19 +192,23 @@ func (c *Cache) getRemPieces() []*Piece {
|
||||
if p.Size > 0 {
|
||||
fill += p.Size
|
||||
}
|
||||
piece := c.torrent.Piece(id)
|
||||
state := piece.State()
|
||||
if len(ranges) > 0 {
|
||||
if !inRanges(ranges, id) {
|
||||
piece := c.torrent.Piece(id)
|
||||
if piece.State().Priority != torrent.PiecePriorityNone {
|
||||
if state.Priority != torrent.PiecePriorityNone {
|
||||
piece.SetPriority(torrent.PiecePriorityNone)
|
||||
}
|
||||
if p.Size > 0 {
|
||||
piecesRemove = append(piecesRemove, p)
|
||||
}
|
||||
} else {
|
||||
if state.Priority != torrent.PiecePriorityNow && state.Priority != torrent.PiecePriorityReadahead && state.Priority != torrent.PiecePriorityNormal {
|
||||
piece.SetPriority(torrent.PiecePriorityNormal)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
piece := c.torrent.Piece(id)
|
||||
if piece.State().Priority != torrent.PiecePriorityNone {
|
||||
if state.Priority != torrent.PiecePriorityNone {
|
||||
piece.SetPriority(torrent.PiecePriorityNone)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ type Reader struct {
|
||||
|
||||
///Preload
|
||||
muPreload sync.Mutex
|
||||
ranges Range
|
||||
}
|
||||
|
||||
func newReader(file *torrent.File, cache *Cache) *Reader {
|
||||
@@ -60,7 +61,7 @@ func (r *Reader) Read(p []byte) (n int, err error) {
|
||||
if r.file.Torrent() != nil && r.file.Torrent().Info() != nil {
|
||||
n, err = r.Reader.Read(p)
|
||||
r.offset += int64(n)
|
||||
go r.preload()
|
||||
//go r.preload()
|
||||
} else {
|
||||
log.TLogln("Torrent closed and readed")
|
||||
}
|
||||
|
||||
@@ -40,8 +40,13 @@ func (r *Reader) getOffsetRange() (int64, int64) {
|
||||
}
|
||||
|
||||
func (r *Reader) preload() {
|
||||
torr := r.file.Torrent()
|
||||
rrange := r.getPiecesRange()
|
||||
if rrange.Start == r.ranges.Start && rrange.End == r.ranges.End {
|
||||
return
|
||||
}
|
||||
|
||||
torr := r.file.Torrent()
|
||||
r.ranges = rrange
|
||||
rahPiece := int(r.readahead / torr.Info().PieceLength)
|
||||
readerPiece := r.getReaderPiece()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user