mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-20 05:56:10 +05:00
fix remove pieces
This commit is contained in:
@@ -90,21 +90,21 @@ func (b *BufferPool) ReleaseBuffer(index int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *BufferPool) Used() map[int]struct{} {
|
//func (b *BufferPool) Used() map[int]struct{} {
|
||||||
b.mu.Lock()
|
// b.mu.Lock()
|
||||||
defer b.mu.Unlock()
|
// defer b.mu.Unlock()
|
||||||
if len(b.buffs) == 0 {
|
// if len(b.buffs) == 0 {
|
||||||
b.mkBuffs()
|
// b.mkBuffs()
|
||||||
}
|
// }
|
||||||
used := make(map[int]struct{})
|
// used := make(map[int]struct{})
|
||||||
for _, b := range b.buffs {
|
// for _, b := range b.buffs {
|
||||||
if b.used {
|
// if b.used {
|
||||||
used[b.pieceId] = struct{}{}
|
// used[b.pieceId] = struct{}{}
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return used
|
// return used
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
func (b *BufferPool) Len() int {
|
//func (b *BufferPool) Len() int {
|
||||||
return b.frees
|
// return b.frees
|
||||||
}
|
//}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ type Cache struct {
|
|||||||
|
|
||||||
pieces map[int]*Piece
|
pieces map[int]*Piece
|
||||||
bufferPull *BufferPool
|
bufferPull *BufferPool
|
||||||
|
usedPieces map[int]struct{}
|
||||||
|
|
||||||
readers map[*reader.Reader]struct{}
|
readers map[*reader.Reader]struct{}
|
||||||
}
|
}
|
||||||
@@ -42,6 +43,7 @@ func NewCache(capacity int64, storage *Storage) *Cache {
|
|||||||
filled: 0,
|
filled: 0,
|
||||||
pieces: make(map[int]*Piece),
|
pieces: make(map[int]*Piece),
|
||||||
readers: make(map[*reader.Reader]struct{}),
|
readers: make(map[*reader.Reader]struct{}),
|
||||||
|
usedPieces: make(map[int]struct{}),
|
||||||
s: storage,
|
s: storage,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,13 +161,12 @@ func (c *Cache) cleanPieces() {
|
|||||||
func (c *Cache) getBufferedPieces() map[int]*Piece {
|
func (c *Cache) getBufferedPieces() map[int]*Piece {
|
||||||
pieces := make(map[int]*Piece)
|
pieces := make(map[int]*Piece)
|
||||||
fill := int64(0)
|
fill := int64(0)
|
||||||
used := c.bufferPull.Used()
|
used := c.usedPieces
|
||||||
for u := range used {
|
for u := range used {
|
||||||
piece := c.pieces[u]
|
piece := c.pieces[u]
|
||||||
if piece.Size > 0 {
|
if piece.Size > 0 {
|
||||||
if piece.Id > 0 {
|
if piece.Id > 0 {
|
||||||
pieces[piece.Id] = piece
|
pieces[piece.Id] = piece
|
||||||
//pieces = append(pieces, piece)
|
|
||||||
}
|
}
|
||||||
fill += piece.Size
|
fill += piece.Size
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ func (p *Piece) WriteAt(b []byte, off int64) (n int, err error) {
|
|||||||
if p.buffer == nil {
|
if p.buffer == nil {
|
||||||
return 0, errors.New("Can't get buffer write")
|
return 0, errors.New("Can't get buffer write")
|
||||||
}
|
}
|
||||||
|
p.cache.usedPieces[p.Id] = struct{}{}
|
||||||
}
|
}
|
||||||
n = copy(p.buffer[off:], b[:])
|
n = copy(p.buffer[off:], b[:])
|
||||||
p.Size += int64(n)
|
p.Size += int64(n)
|
||||||
@@ -101,6 +102,9 @@ func (p *Piece) Release() {
|
|||||||
}
|
}
|
||||||
p.Size = 0
|
p.Size = 0
|
||||||
p.complete = false
|
p.complete = false
|
||||||
|
if _, ok := p.cache.usedPieces[p.Id]; ok {
|
||||||
|
delete(p.cache.usedPieces, p.Id)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Piece) Stat() state.ItemState {
|
func (p *Piece) Stat() state.ItemState {
|
||||||
|
|||||||
Reference in New Issue
Block a user