mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 21:46:11 +05:00
fix reader clean priority
This commit is contained in:
@@ -213,11 +213,6 @@ func (c *Cache) cleanPieces() {
|
||||
c.muRemove.Unlock()
|
||||
|
||||
remPieces := c.getRemPieces()
|
||||
for _, p := range remPieces {
|
||||
if c.torrent.Piece(p.Id).State().Priority == torrent.PiecePriorityNone {
|
||||
c.torrent.Piece(p.Id).SetPriority(torrent.PiecePriorityNormal)
|
||||
}
|
||||
}
|
||||
if c.filled > c.capacity {
|
||||
rems := (c.filled - c.capacity) / c.pieceLength
|
||||
for _, p := range remPieces {
|
||||
@@ -234,10 +229,6 @@ func (c *Cache) getRemPieces() []*Piece {
|
||||
piecesRemove := make([]*Piece, 0)
|
||||
fill := int64(0)
|
||||
|
||||
for id, p := range c.pieces {
|
||||
if p.Size > 0 {
|
||||
fill += p.Size
|
||||
|
||||
ranges := make([]Range, 0)
|
||||
c.muReaders.Lock()
|
||||
for r, _ := range c.readers {
|
||||
@@ -246,12 +237,24 @@ func (c *Cache) getRemPieces() []*Piece {
|
||||
c.muReaders.Unlock()
|
||||
ranges = mergeRange(ranges)
|
||||
|
||||
for id, p := range c.pieces {
|
||||
if len(ranges) > 0 {
|
||||
for _, rr := range ranges {
|
||||
if id < rr.Start || id > rr.End {
|
||||
if c.torrent.Piece(id).State().Priority != torrent.PiecePriorityNone {
|
||||
c.torrent.Piece(id).SetPriority(torrent.PiecePriorityNone)
|
||||
}
|
||||
if p.Size > 0 {
|
||||
fill += p.Size
|
||||
piecesRemove = append(piecesRemove, p)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if c.torrent.Piece(id).State().Priority != torrent.PiecePriorityNone {
|
||||
c.torrent.Piece(id).SetPriority(torrent.PiecePriorityNone)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sort.Slice(piecesRemove, func(i, j int) bool {
|
||||
|
||||
@@ -94,6 +94,7 @@ func (r *Reader) Close() {
|
||||
r.mu.Lock()
|
||||
r.isClosed = true
|
||||
r.mu.Unlock()
|
||||
go r.cache.getRemPieces()
|
||||
}
|
||||
|
||||
func (c *Cache) NewReader(file *torrent.File) *Reader {
|
||||
|
||||
Reference in New Issue
Block a user