updates on multithreading
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
Paul 2023-09-16 09:53:56 +02:00
parent ee28c124a0
commit f3b5711135

View File

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