From 5a61660567264ac5ce43829844612c1b65bc0a18 Mon Sep 17 00:00:00 2001 From: Paul Lecuq Date: Sun, 30 Jan 2022 23:48:13 +0100 Subject: [PATCH] update selecting trigger --- src/models/ip.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/models/ip.go b/src/models/ip.go index a3e7452..af1d57d 100644 --- a/src/models/ip.go +++ b/src/models/ip.go @@ -25,7 +25,7 @@ func GetIPs(ctx *context.Context, config *config.Config, limit int) (apimailboxe // GetIPs ... func GetIPsLastDay(ctx *context.Context, config *config.Config, interval string) (apimailboxes []*api.IP, err error) { var ips []IP - err = config.Db.Where(fmt.Sprintf("created >= (now()-'%s'::interval)", interval)).Desc("created").Find(&ips) + err = config.Db.Where(fmt.Sprintf("updated >= (now()-'%s'::interval)", interval)).Asc("id").Find(&ips) for _, ml := range ips { apimailboxes = append(apimailboxes, ml.APIFormat()) } @@ -66,16 +66,19 @@ func (i *IP) InsertIP(cfg *config.Config) (num int64, err error) { // InsertIPBulk ... func InsertIPBulk(cfg *config.Config, ips *[]IP) (numinserts int64, numupdates int64, numfail int64, err error) { + lastday := time.Now().Add(-(time.Hour * 24)) for _, ip := range *ips { s_ip := IP{IP: ip.IP} res, _ := cfg.Db.Get(&s_ip) if res { - num, err := cfg.Db.ID(s_ip.ID).Update(&s_ip) - if err != nil { - numfail++ - continue + if !s_ip.Updated.After(lastday) { + num, err := cfg.Db.ID(s_ip.ID).Update(&s_ip) + if err != nil { + numfail++ + continue + } + numupdates += num } - numupdates += num } else { num, err := cfg.Db.Insert(ip) if err != nil {