From 4ec66929b0ae627999d6098c2dbf65e2bbf45a44 Mon Sep 17 00:00:00 2001 From: YouROK <8yourok8@mail.ru> Date: Fri, 12 Mar 2021 15:50:58 +0300 Subject: [PATCH] change load strategy, thx @antibaks --- server/torr/storage/torrstor/cache.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) 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 })