From abc3b8df56158b329c8cf85d6a08e5c7252de09b Mon Sep 17 00:00:00 2001 From: nikk gitanes Date: Wed, 18 Aug 2021 04:35:05 +0300 Subject: [PATCH] improve priority logic --- server/torr/storage/torrstor/cache.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/server/torr/storage/torrstor/cache.go b/server/torr/storage/torrstor/cache.go index 2686ea8..54474b8 100644 --- a/server/torr/storage/torrstor/cache.go +++ b/server/torr/storage/torrstor/cache.go @@ -247,7 +247,7 @@ func (c *Cache) getRemPieces() []*Piece { } pc := r.getReaderPiece() end := r.getPiecesRange().End - limit := 16777216 / c.pieceLength * 5 + limit := 16777216 / c.pieceLength * 5 // 80 MB if limit > 40 { limit = 40 } @@ -256,7 +256,11 @@ func (c *Cache) getRemPieces() []*Piece { for pc <= end && limit > 0 { if !c.pieces[pc].Complete { if c.torrent.PieceState(pc).Priority == torrent.PiecePriorityNone { - if limit > count/2 { + if limit = 1 { + c.torrent.Piece(pc).SetPriority(torrent.PiecePriorityNext) + } else if limit < 4 { + c.torrent.Piece(pc).SetPriority(torrent.PiecePriorityReadahead) + } else if limit < count/2 { c.torrent.Piece(pc).SetPriority(torrent.PiecePriorityHigh) } else { c.torrent.Piece(pc).SetPriority(torrent.PiecePriorityNormal)