Skip to content

Commit

Permalink
add time check capability to GetAllCached
Browse files Browse the repository at this point in the history
  • Loading branch information
AmyrAhmady committed Oct 4, 2023
1 parent edee5f9 commit 664c4f2
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/resources/server/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ func (s *DB) SetDeleted(ctx context.Context, ip string, at *time.Time) (*All, er

func (s *DB) GetAllCached(updatedSince time.Duration) ([]All, error) {
result := []All{}
list := []All{}
dat, err := os.ReadFile(s.cfg.CachedServers)
if err != nil {
return nil, err
Expand All @@ -181,7 +182,13 @@ func (s *DB) GetAllCached(updatedSince time.Duration) ([]All, error) {
return nil, err
}

return result, nil
for idx := range result {
if result[idx].LastUpdated.After(time.Now().Add(updatedSince)) {
list = append(list, result[idx])
}
}

return list, nil
}

func (s *DB) GetByAddressCached(address string) (*All, error) {
Expand Down

0 comments on commit 664c4f2

Please sign in to comment.