Ver código fonte

fix(internal/repository): 修复获取 gatewayip 逻辑

- 在 GetGatewayipByHostIdFirst 函数中添加 Model 指定查询的模型
- 优化查询性能,避免全表扫描
fusu 3 semanas atrás
pai
commit
a48575306c
1 arquivos alterados com 1 adições e 1 exclusões
  1. 1 1
      internal/repository/gatewayip.go

+ 1 - 1
internal/repository/gatewayip.go

@@ -53,7 +53,7 @@ func (r *gatewayipRepository) DeleteGatewayip(ctx context.Context, req model.Gat
 
 func (r *gatewayipRepository) GetGatewayipByHostIdFirst(ctx context.Context, hostId int64) (string, error) {
 	var req string
-	return req, r.DB(ctx).Where("host_id = ?", hostId).Pluck("ip", &req).Error
+	return req, r.DB(ctx).Model(&model.Gatewayip{}).Where("host_id = ?", hostId).Pluck("ip", &req).Error
 }
 
 func (r *gatewayipRepository) GetGatewayipByHostIdAll(ctx context.Context, hostId int64) (*model.Gatewayip, error) {