update selecting trigger
This commit is contained in:
parent
fb45356a08
commit
5a61660567
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user