From f946512f64f1e2e9aa887f62f04f8ebedb53d810 Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期三, 22 五月 2024 15:20:21 +0800
Subject: [PATCH] 优化重传, 修改为每次读取一条记录

---
 models/cache.go |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/models/cache.go b/models/cache.go
index 5aea0ef..5c0dd44 100644
--- a/models/cache.go
+++ b/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
 }

--
Gitblit v1.8.0