go routines for Db query

This commit is contained in:
2024-10-24 21:58:29 +07:00
parent 6bef3f45cd
commit 09e9c9ef80
4 changed files with 61 additions and 51 deletions

35
spot.go
View File

@ -4,6 +4,7 @@ import (
"regexp"
"strconv"
"strings"
"sync"
_ "github.com/mattn/go-sqlite3"
)
@ -49,20 +50,30 @@ func ProcessTelnetSpot(re *regexp.Regexp, spotRaw string, SpotChanToFlex chan Te
contactRepo := NewLog4OMContactsRepository(Cfg.SQLite.SQLitePath)
defer contactRepo.db.Close()
contacts, _ := contactRepo.ListByCountry(spot.DXCC)
contactsMode, _ := contactRepo.ListByCountryMode(spot.DXCC, spot.Mode)
contactsBand, _ := contactRepo.ListByCountryBand(spot.DXCC, spot.Band)
contactsCall, _ := contactRepo.ListByCallSign(spot.DX, spot.Band, spot.Mode)
contactsChan := make(chan []Contact)
contactsModeChan := make(chan []Contact)
contactsBandChan := make(chan []Contact)
contactsCallChan := make(chan []Contact)
wg := new(sync.WaitGroup)
wg.Add(4)
go contactRepo.ListByCountry(spot.DXCC, contactsChan, wg)
contacts := <-contactsChan
go contactRepo.ListByCountryMode(spot.DXCC, spot.Mode, contactsModeChan, wg)
contactsMode := <-contactsModeChan
go contactRepo.ListByCountryBand(spot.DXCC, spot.Band, contactsBandChan, wg)
contactsBand := <-contactsBandChan
go contactRepo.ListByCallSign(spot.DX, spot.Band, spot.Mode, contactsCallChan, wg)
contactsCall := <-contactsCallChan
wg.Wait()
if len(contacts) == 0 {
switch spot.DXCC {
case "997":
spot.NewDXCC = false
case "1000":
spot.NewDXCC = false
default:
spot.NewDXCC = true
}
spot.NewDXCC = true
}
if len(contactsMode) == 0 {