mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-06 01:50:25 +08:00
优化过期IP清理
This commit is contained in:
@@ -444,7 +444,7 @@ func (this *IPItemDAO) CleanExpiredIPItems(tx *dbs.Tx) error {
|
|||||||
Where("(expiredAt>0 AND expiredAt<=:timestamp)").
|
Where("(expiredAt>0 AND expiredAt<=:timestamp)").
|
||||||
Param("timestamp", time.Now().Unix()).
|
Param("timestamp", time.Now().Unix()).
|
||||||
State(IPItemStateEnabled).
|
State(IPItemStateEnabled).
|
||||||
Limit(100).
|
Limit(500).
|
||||||
FindOnes()
|
FindOnes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
"github.com/iwind/TeaGo/dbs"
|
"github.com/iwind/TeaGo/dbs"
|
||||||
"github.com/iwind/TeaGo/rands"
|
"github.com/iwind/TeaGo/rands"
|
||||||
@@ -47,16 +48,17 @@ func TestIPItemDAO_CreateManyIPs(t *testing.T) {
|
|||||||
|
|
||||||
var tx *dbs.Tx
|
var tx *dbs.Tx
|
||||||
var dao = NewIPItemDAO()
|
var dao = NewIPItemDAO()
|
||||||
var n = 5
|
var n = 10
|
||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
itemId, err := dao.CreateIPItem(tx, 1, "192."+types.String(rands.Int(0, 255))+"."+types.String(rands.Int(0, 255))+"."+types.String(rands.Int(0, 255)), "", time.Now().Unix()-86400, "test", IPItemTypeIPv4, "warning", 0, 0, 0, 0, 0, 0, 0)
|
itemId, err := dao.CreateIPItem(tx, firewallconfigs.GlobalListId, "192."+types.String(rands.Int(0, 255))+"."+types.String(rands.Int(0, 255))+"."+types.String(rands.Int(0, 255)), "", time.Now().Unix()+86400, "test", IPItemTypeIPv4, "warning", 0, 0, 0, 0, 0, 0, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
err = dao.Query(tx).Pk(itemId).Set("state", 0).UpdateQuickly()
|
_ = itemId
|
||||||
|
/**err = dao.Query(tx).Pk(itemId).Set("state", 0).UpdateQuickly()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}**/
|
||||||
}
|
}
|
||||||
t.Log("ok")
|
t.Log("ok")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ func init() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 开锁
|
// Lock 开锁
|
||||||
func (this *SysLockerDAO) Lock(tx *dbs.Tx, key string, timeout int64) (ok bool, err error) {
|
func (this *SysLockerDAO) Lock(tx *dbs.Tx, key string, timeout int64) (ok bool, err error) {
|
||||||
maxErrors := 5
|
maxErrors := 5
|
||||||
for {
|
for {
|
||||||
@@ -103,7 +103,7 @@ func (this *SysLockerDAO) Lock(tx *dbs.Tx, key string, timeout int64) (ok bool,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解锁
|
// Unlock 解锁
|
||||||
func (this *SysLockerDAO) Unlock(tx *dbs.Tx, key string) error {
|
func (this *SysLockerDAO) Unlock(tx *dbs.Tx, key string) error {
|
||||||
_, err := this.Query(tx).
|
_, err := this.Query(tx).
|
||||||
Attr("key", key).
|
Attr("key", key).
|
||||||
@@ -112,7 +112,7 @@ func (this *SysLockerDAO) Unlock(tx *dbs.Tx, key string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 增加版本号
|
// Increase 增加版本号
|
||||||
func (this *SysLockerDAO) Increase(tx *dbs.Tx, key string, defaultValue int64) (int64, error) {
|
func (this *SysLockerDAO) Increase(tx *dbs.Tx, key string, defaultValue int64) (int64, error) {
|
||||||
if tx == nil {
|
if tx == nil {
|
||||||
var result int64
|
var result int64
|
||||||
|
|||||||
Reference in New Issue
Block a user