client.go | 4 +++- torrent.go | 6 +++++- diff --git a/client.go b/client.go index 663d1a01319ab1e1912a8b3c3ebb90491f12ac45..6d86c41af4e30b18724eefbc1d2082b40f3e7954 100644 --- a/client.go +++ b/client.go @@ -2497,7 +2497,9 @@ me.onCompletedPiece(t, piece) } else { me.onFailedPiece(t, piece) } - t.updatePiecePriority(piece) + if t.updatePiecePriority(piece) { + t.piecePriorityChanged(piece) + } t.publishPieceChange(piece) } diff --git a/torrent.go b/torrent.go index 01bc9005f4e98336a5dc539af953c25c1e0c6783..c8e5e5ba3d351256d0e54432333940b0a264183b 100644 --- a/torrent.go +++ b/torrent.go @@ -860,6 +860,8 @@ p.priority = newPrio return true } +// Update all piece priorities in one hit. This function should have the same +// output as updatePiecePriority, but across all pieces. func (t *torrent) updatePiecePriorities() { newPrios := make([]piecePriority, t.numPieces()) t.pendingPieces.IterTyped(func(piece int) (more bool) { @@ -875,8 +877,10 @@ newPrios[i].Raise(PiecePriorityReadahead) } return true }) - // TODO: Do I need a pass suppressing stuff that we already have? for i, prio := range newPrios { + if t.pieceComplete(i) { + prio = PiecePriorityNone + } if prio != t.Pieces[i].priority { t.Pieces[i].priority = prio t.piecePriorityChanged(i)