mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 13:36:09 +05:00
change cache priority logic
This commit is contained in:
@@ -247,26 +247,28 @@ func (c *Cache) getRemPieces() []*Piece {
|
|||||||
if c.isIdInFileBE(ranges, r.getReaderPiece()) {
|
if c.isIdInFileBE(ranges, r.getReaderPiece()) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
pc := r.getReaderPiece()
|
readerPos := r.getReaderPiece()
|
||||||
|
readerRAHPos := r.getReaderRAHPiece()
|
||||||
end := r.getPiecesRange().End
|
end := r.getPiecesRange().End
|
||||||
limit := 16777216 / c.pieceLength * 5 // 80 MB
|
count := int(16777216 / c.pieceLength * 5) // 80 MB
|
||||||
if limit > 40 {
|
if count > 40 {
|
||||||
limit = 40
|
count = 40
|
||||||
}
|
}
|
||||||
count := limit
|
limit := 0
|
||||||
|
|
||||||
for pc <= end && limit > 0 {
|
for i := readerPos; i < end && limit < count; i++ {
|
||||||
if !c.pieces[pc].Complete {
|
if !c.pieces[i].Complete {
|
||||||
if c.torrent.PieceState(pc).Priority == torrent.PiecePriorityNone {
|
if i == readerPos {
|
||||||
if limit < count/2 {
|
c.torrent.Piece(i).SetPriority(torrent.PiecePriorityNow)
|
||||||
c.torrent.Piece(pc).SetPriority(torrent.PiecePriorityHigh)
|
} else if i > readerPos && i <= readerRAHPos {
|
||||||
} else {
|
c.torrent.Piece(i).SetPriority(torrent.PiecePriorityReadahead)
|
||||||
c.torrent.Piece(pc).SetPriority(torrent.PiecePriorityNormal)
|
} else if i > readerRAHPos && i <= end/2 && c.torrent.PieceState(i).Priority != torrent.PiecePriorityHigh {
|
||||||
}
|
c.torrent.Piece(i).SetPriority(torrent.PiecePriorityHigh)
|
||||||
|
} else if i > end/2 && c.torrent.PieceState(i).Priority != torrent.PiecePriorityNormal {
|
||||||
|
c.torrent.Piece(i).SetPriority(torrent.PiecePriorityNormal)
|
||||||
}
|
}
|
||||||
limit--
|
limit++
|
||||||
}
|
}
|
||||||
pc++
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.muReaders.Unlock()
|
c.muReaders.Unlock()
|
||||||
|
|||||||
@@ -125,8 +125,11 @@ func (r *Reader) getPiecesRange() Range {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Reader) getReaderPiece() int {
|
func (r *Reader) getReaderPiece() int {
|
||||||
readerOff := r.offset
|
return r.getPieceNum(r.offset)
|
||||||
return r.getPieceNum(readerOff)
|
}
|
||||||
|
|
||||||
|
func (r *Reader) getReaderRAHPiece() int {
|
||||||
|
return r.getPieceNum(r.offset + r.readahead)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Reader) getPieceNum(offset int64) int {
|
func (r *Reader) getPieceNum(offset int64) int {
|
||||||
|
|||||||
Reference in New Issue
Block a user