From b6731f8442be8f6bd1d68f1f411f3d2ed8755ba3 Mon Sep 17 00:00:00 2001 From: luorijun Date: Sat, 16 Aug 2025 18:38:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9B=B4=E6=96=B0=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E6=97=B6=E5=B9=B6=E5=8F=91=E5=AF=BC=E8=87=B4=E7=9A=84?= =?UTF-8?q?=E5=88=86=E9=85=8D=E5=A4=B1=E8=B4=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- actions/cities.go | 2 +- actions/update.go | 8 ++++++++ cmd/tmp.go | 15 --------------- 3 files changed, 9 insertions(+), 16 deletions(-) delete mode 100644 cmd/tmp.go diff --git a/actions/cities.go b/actions/cities.go index 4b416af..0c943de 100644 --- a/actions/cities.go +++ b/actions/cities.go @@ -20,7 +20,7 @@ func FindCitiesWithEdgesCount(tx *gorm.DB) ([]model.City, error) { model.City EdgesCount int `gorm:"column:edges_count"` } - err := tx.Debug(). + err := tx. Select("cityhash.*, COUNT(edge.id) AS edges_count"). Joins("LEFT JOIN edge ON edge.city_id = cityhash.id"). Where("cityhash.label IS NOT NULL"). diff --git a/actions/update.go b/actions/update.go index cc238d2..7950a20 100644 --- a/actions/update.go +++ b/actions/update.go @@ -94,6 +94,14 @@ func Update(args ...UpdateArgs) error { if err != nil { return fmt.Errorf("查询城市 %s 可用节点失败:%w", city.Name, err) } + if len(edges) < count { + slog.Debug("城市节点不足,将循环使用节点", "城市", city.Name, "节点数", city.EdgesCount, "网关数", count) + edges, err = SliceActiveEdgesByCity(tx, city.Id, 0, count) + if err != nil { + return fmt.Errorf("查询城市 %s 可用节点失败:%w", city.Name, err) + } + offset = 0 + } // 更新网关配置 var configs2Create []model.Config diff --git a/cmd/tmp.go b/cmd/tmp.go deleted file mode 100644 index c12d434..0000000 --- a/cmd/tmp.go +++ /dev/null @@ -1,15 +0,0 @@ -package main - -func main() { - //slog.Debug("初始化环境变量") - //err := godotenv.Load() - //if err != nil { - // slog.Error(fmt.Errorf("初始化变量失败:%w", err).Error()) - //} - // - //model.Init() - //clients.InitRedis() - // - //cities, _ := actions.FindCitiesWithEdgesCount(model.DB) - //fmt.Printf("%v\n", cities) -}