zhangzengfei
2024-05-22 f946512f64f1e2e9aa887f62f04f8ebedb53d810
优化重传, 修改为每次读取一条记录
2个文件已修改
25 ■■■■ 已修改文件
models/cache.go 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/resend.go 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/cache.go
@@ -12,6 +12,10 @@
    return "caches"
}
func (c *Cache) First() error {
    return db.Table(c.TableName()).First(c).Error
}
func (c *Cache) FindAll() ([]Cache, error) {
    var caches []Cache
    if err := db.Table(c.TableName()).Find(&caches).Error; err != nil {
@@ -21,6 +25,15 @@
    return caches, nil
}
func (c *Cache) Count() (int64, error) {
    var total int64
    if err := db.Table(c.TableName()).Count(&total).Error; err != nil {
        return total, err
    }
    return total, nil
}
func (c *Cache) Save() error {
    return db.Table(c.TableName()).Save(c).Error
}
service/resend.go
@@ -11,10 +11,16 @@
func ResendImageData() {
    var cacheMod models.Cache
    cacheItems, _ := cacheMod.FindAll()
    logger.Debug("Start resend task. cache len:%d", len(cacheItems))
    total, _ := cacheMod.Count()
    logger.Debug("Start resend task. cache len:%d", total)
    for _, c := range cacheItems {
    for i := 0; i < int(total); i++ {
        var c models.Cache
        err := c.First()
        if err != nil {
            logger.Error(err.Error())
            return
        }
        if c.Type == "1400" {
            if client.FaceCapture([]byte(c.Data)) != vo.StatusSuccess {
                c.UpdateRetryCount()