mirror of
https://github.com/bitmagnet-io/bitmagnet.git
synced 2026-07-24 21:21:03 -04:00
85bf13bc6a
- Add a stable bloom filter, stored in the database, for blocked and deleted torrents - Add GraphQL mutations for blocking and deleting torrents - Add web UI for bulk actions (tagging and deleting) - Some minor cosmetic web UI tweaks - Move database operations to dao package
40 lines
831 B
Go
40 lines
831 B
Go
package bloom
|
|
|
|
import (
|
|
"database/sql/driver"
|
|
"errors"
|
|
boom "github.com/tylertreat/BoomFilters"
|
|
)
|
|
|
|
type StableBloomFilter struct {
|
|
boom.StableBloomFilter
|
|
}
|
|
|
|
const defaultCapacity = 100_000_000
|
|
const defaultD = 2
|
|
const defaultFpRate = 0.001
|
|
|
|
func NewDefaultStableBloomFilter() *StableBloomFilter {
|
|
return &StableBloomFilter{*boom.NewStableBloomFilter(defaultCapacity, defaultD, defaultFpRate)}
|
|
}
|
|
|
|
func (s *StableBloomFilter) Scan(value interface{}) error {
|
|
bytes, ok := value.([]byte)
|
|
if !ok {
|
|
return errors.New("invalid type for StableBloomFilter")
|
|
}
|
|
bf := boom.NewStableBloomFilter(0, 0, 0)
|
|
if err := bf.GobDecode(bytes); err != nil {
|
|
return err
|
|
}
|
|
s.StableBloomFilter = *bf
|
|
return nil
|
|
}
|
|
|
|
func (s StableBloomFilter) Value() (driver.Value, error) {
|
|
if s.Cells() == 0 {
|
|
return nil, nil
|
|
}
|
|
return s.GobEncode()
|
|
}
|