소스 검색

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

- 在 GetGatewayipByHostIdFirst 函数中添加 Model 指定查询的模型
- 优化查询性能,避免全表扫描
fusu 3 주 전
부모
커밋
a48575306c
1개의 변경된 파일1개의 추가작업 그리고 1개의 파일을 삭제
  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) {