some cleanup

This commit is contained in:
Balakrishnan Balasubramanian 2022-06-02 02:09:59 -04:00
parent 315efbd072
commit f3ac9f621c
2 changed files with 11 additions and 13 deletions

View File

@ -48,8 +48,10 @@ func (d *db) IsNewFeed() bool {
func NewDB(storageDir, feedName string) (DB, error) { func NewDB(storageDir, feedName string) (DB, error) {
dbPath := path.Join(storageDir, fmt.Sprintf("%s.csv", feedName)) dbPath := path.Join(storageDir, fmt.Sprintf("%s.csv", feedName))
db := db{dbPath: dbPath} db := db{
db.seenLinks = map[string]struct{}{} dbPath: dbPath,
seenLinks: map[string]struct{}{},
}
f, err := os.Open(dbPath) f, err := os.Open(dbPath)
if err != nil { if err != nil {
if errors.Is(err, os.ErrNotExist) { if errors.Is(err, os.ErrNotExist) {

View File

@ -11,22 +11,18 @@ type Limiter interface {
type limiter struct { type limiter struct {
tick time.Duration tick time.Duration
count uint count int
entries []time.Time entries []time.Time
index uint index int
mutex sync.Mutex mutex sync.Mutex
} }
func NewLimiter(tick time.Duration, count uint) Limiter { func NewLimiter(tick time.Duration, count int) Limiter {
l := limiter{ l := limiter{
tick: tick, tick: tick,
count: count, count: count,
index: 0, entries: make([]time.Time, count),
} index: 0,
l.entries = make([]time.Time, count)
before := time.Now().Add(-2 * tick)
for i, _ := range l.entries {
l.entries[i] = before
} }
return &l return &l
} }