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