updates on multithreading #3

Merged
paulbsd merged 1 commits from develop into master 2023-09-16 09:57:43 +02:00

View File

@ -155,15 +155,14 @@ func ScanIP(cfg *config.Config) (err error) {
AND rdns IS NULL
)
`).Desc("updated").Limit(SCANLIMIT).Find(&orphans)
defer session.Close()
session.Close()
if err == nil && len(orphans) > 0 {
orphanchan := make(chan IP)
done := make(chan bool)
var wg sync.WaitGroup
for thr := range make([]int, numthreads) {
go ScanOrphan(&wg, orphanchan, done, thr, cfg)
go ScanOrphan(&wg, orphanchan, thr, cfg)
}
for _, orphan := range orphans {
@ -173,12 +172,12 @@ func ScanIP(cfg *config.Config) (err error) {
close(orphanchan)
wg.Wait()
} else {
time.Sleep(1 * time.Second)
time.Sleep(2 * time.Second)
}
}
}
func ScanOrphan(wg *sync.WaitGroup, orphans chan IP, done chan bool, thr int, cfg *config.Config) (err error) {
func ScanOrphan(wg *sync.WaitGroup, orphans chan IP, thr int, cfg *config.Config) (err error) {
wg.Add(1)
session := cfg.Db.NewSession()
@ -223,7 +222,7 @@ func ScanOrphan(wg *sync.WaitGroup, orphans chan IP, done chan bool, thr int, cf
}
} else {
fmt.Printf("All orphan migrated on thread num %d\n", thr)
log.Printf("All orphan migrated on thread num %d\n", thr)
wg.Done()
break
}
@ -297,12 +296,12 @@ func (ip *APIIP) BeforeInsert() (err error) {
type IP struct {
ID int `xorm:"pk autoincr"`
IP string `xorm:"text notnull"`
Rdns sql.NullString `xorm:"text default ''"`
Rdns sql.NullString `xorm:"text index default ''"`
AutonomousSystem *AutonomousSystem `xorm:"as_id int index default null"`
City *City `xorm:"city_id int index default null"`
Country *Country `xorm:"country_id int index default null"`
Created time.Time `xorm:"created notnull"`
Updated time.Time `xorm:"updated notnull"`
Updated time.Time `xorm:"updated index notnull"`
}
type APIIP struct {