update selecting trigger
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone Build is failing
continuous-integration/drone/tag Build is passing

This commit is contained in:
Paul 2022-01-30 23:48:13 +01:00
parent fb45356a08
commit 5a61660567

View File

@ -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 {