From f3b5711135efd8f78b491bec69c7c286091615a2 Mon Sep 17 00:00:00 2001 From: Paul Lecuq Date: Sat, 16 Sep 2023 09:53:56 +0200 Subject: [PATCH] updates on multithreading --- src/models/ip.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/models/ip.go b/src/models/ip.go index 55eba6d..9ca914e 100644 --- a/src/models/ip.go +++ b/src/models/ip.go @@ -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 { -- 2.39.5