Skip to content

Commit

Permalink
hosts parser: only run one parser instance
Browse files Browse the repository at this point in the history
  • Loading branch information
USA-RedDragon committed Feb 21, 2024
1 parent 3eb0b2f commit a0b5ce1
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions internal/olsrd/hosts_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import (
"net/url"
"os"
"strings"
"sync/atomic"
)

const hostsFile = "/var/run/hosts_olsr"

type HostsParser struct {
currentHosts []*AREDNHost
isParsing atomic.Bool
}

func NewHostsParser() *HostsParser {
Expand Down Expand Up @@ -47,6 +49,11 @@ func (p *HostsParser) GetHostsPaginated(page int, limit int, filter string) []*A
}

func (p *HostsParser) Parse() (err error) {
if p.isParsing.Load() {
return
}
p.isParsing.Store(true)
defer p.isParsing.Store(false)
hosts, err := parseHosts()
if err != nil {
return
Expand Down

0 comments on commit a0b5ce1

Please sign in to comment.