diff --git a/server/torr/storage/torrstor/cache.go b/server/torr/storage/torrstor/cache.go index 566476f..3d3a494 100644 --- a/server/torr/storage/torrstor/cache.go +++ b/server/torr/storage/torrstor/cache.go @@ -200,14 +200,26 @@ func (c *Cache) getRemPieces() []*Piece { if p.Size > 0 && !c.isIdInFileBE(ranges, id) { piecesRemove = append(piecesRemove, p) } - } else { - if c.torrent.PieceState(id).Priority == torrent.PiecePriorityNone { - c.torrent.Piece(id).SetPriority(torrent.PiecePriorityNormal) - } } } } + for r, _ := range c.readers { + pc := r.getReaderPiece() + end := r.getPiecesRange().End + limit := 5 + + for pc <= end && limit > 0 { + if !c.pieces[pc].complete { + if c.torrent.PieceState(pc).Priority == torrent.PiecePriorityNone { + c.torrent.Piece(pc).SetPriority(torrent.PiecePriorityNormal) + } + limit-- + } + pc++ + } + } + sort.Slice(piecesRemove, func(i, j int) bool { return piecesRemove[i].accessed < piecesRemove[j].accessed })