mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 13:36:09 +05:00
update piece prior
This commit is contained in:
@@ -201,7 +201,7 @@ func (c *Cache) getRemPieces() []*Piece {
|
|||||||
piecesRemove = append(piecesRemove, p)
|
piecesRemove = append(piecesRemove, p)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if state.Priority != torrent.PiecePriorityNow && state.Priority != torrent.PiecePriorityReadahead && state.Priority != torrent.PiecePriorityNormal {
|
if state.Priority == torrent.PiecePriorityNone {
|
||||||
piece.SetPriority(torrent.PiecePriorityNormal)
|
piece.SetPriority(torrent.PiecePriorityNormal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package torrstor
|
|||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/anacrolix/torrent"
|
"github.com/anacrolix/torrent"
|
||||||
|
|
||||||
@@ -113,6 +114,32 @@ func (c *Cache) CloseReader(r *Reader) {
|
|||||||
r.Close()
|
r.Close()
|
||||||
delete(r.cache.readers, r)
|
delete(r.cache.readers, r)
|
||||||
r.cache.muReaders.Unlock()
|
r.cache.muReaders.Unlock()
|
||||||
|
go c.updatePriority()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Cache) updatePriority() {
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
ranges := make([]Range, 0)
|
||||||
|
c.muReaders.Lock()
|
||||||
|
for r, _ := range c.readers {
|
||||||
|
ranges = append(ranges, r.getPiecesRange())
|
||||||
|
}
|
||||||
|
c.muReaders.Unlock()
|
||||||
|
ranges = mergeRange(ranges)
|
||||||
|
|
||||||
|
for id, _ := range c.pieces {
|
||||||
|
if len(ranges) > 0 {
|
||||||
|
if !inRanges(ranges, id) {
|
||||||
|
if c.torrent.PieceState(id).Priority != torrent.PiecePriorityNone {
|
||||||
|
c.torrent.Piece(id).SetPriority(torrent.PiecePriorityNone)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if c.torrent.PieceState(id).Priority != torrent.PiecePriorityNone {
|
||||||
|
c.torrent.Piece(id).SetPriority(torrent.PiecePriorityNone)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Reader) getPiecesRange() Range {
|
func (r *Reader) getPiecesRange() Range {
|
||||||
|
|||||||
Reference in New Issue
Block a user