fix reader clean priority

This commit is contained in:
YouROK
2020-12-18 17:03:33 +03:00
parent dd92179235
commit bb76523d57
2 changed files with 21 additions and 17 deletions

View File

@@ -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 {

View File

@@ -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 {