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 ...
|
// GetIPs ...
|
||||||
func GetIPsLastDay(ctx *context.Context, config *config.Config, interval string) (apimailboxes []*api.IP, err error) {
|
func GetIPsLastDay(ctx *context.Context, config *config.Config, interval string) (apimailboxes []*api.IP, err error) {
|
||||||
var ips []IP
|
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 {
|
for _, ml := range ips {
|
||||||
apimailboxes = append(apimailboxes, ml.APIFormat())
|
apimailboxes = append(apimailboxes, ml.APIFormat())
|
||||||
}
|
}
|
||||||
@ -66,16 +66,19 @@ func (i *IP) InsertIP(cfg *config.Config) (num int64, err error) {
|
|||||||
|
|
||||||
// InsertIPBulk ...
|
// InsertIPBulk ...
|
||||||
func InsertIPBulk(cfg *config.Config, ips *[]IP) (numinserts int64, numupdates int64, numfail int64, err error) {
|
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 {
|
for _, ip := range *ips {
|
||||||
s_ip := IP{IP: ip.IP}
|
s_ip := IP{IP: ip.IP}
|
||||||
res, _ := cfg.Db.Get(&s_ip)
|
res, _ := cfg.Db.Get(&s_ip)
|
||||||
if res {
|
if res {
|
||||||
num, err := cfg.Db.ID(s_ip.ID).Update(&s_ip)
|
if !s_ip.Updated.After(lastday) {
|
||||||
if err != nil {
|
num, err := cfg.Db.ID(s_ip.ID).Update(&s_ip)
|
||||||
numfail++
|
if err != nil {
|
||||||
continue
|
numfail++
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
numupdates += num
|
||||||
}
|
}
|
||||||
numupdates += num
|
|
||||||
} else {
|
} else {
|
||||||
num, err := cfg.Db.Insert(ip)
|
num, err := cfg.Db.Insert(ip)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user