diff --git a/center/router/router_datasource.go b/center/router/router_datasource.go index 44a2002a..d3d1bca9 100644 --- a/center/router/router_datasource.go +++ b/center/router/router_datasource.go @@ -15,27 +15,17 @@ type listReq struct { Name string `json:"name"` Type string `json:"plugin_type"` Category string `json:"category"` - Limit int `json:"limit"` - P int `json:"p"` } func (rt *Router) datasourceList(c *gin.Context) { var req listReq ginx.BindJSON(c, &req) - if req.Limit == 0 { - req.Limit = 10 - } - if req.P == 0 { - req.P = 1 - } typ := req.Type category := req.Category name := req.Name - limit := req.Limit - p := req.P - list, err := models.GetDatasourcesGetsBy(rt.Ctx, typ, category, name, limit, (p-1)*limit) + list, err := models.GetDatasourcesGetsBy(rt.Ctx, typ, category, name, "") Render(c, list, err) } diff --git a/models/datasource.go b/models/datasource.go index 9b7761af..8e1b9683 100644 --- a/models/datasource.go +++ b/models/datasource.go @@ -158,7 +158,7 @@ func GetDatasourcesCountBy(ctx *ctx.Context, typ, cate, name string) (int64, err return Count(session) } -func GetDatasourcesGetsBy(ctx *ctx.Context, typ, cate, name string, limit, offset int) ([]*Datasource, error) { +func GetDatasourcesGetsBy(ctx *ctx.Context, typ, cate, name, status string) ([]*Datasource, error) { session := DB(ctx) if name != "" { @@ -177,8 +177,12 @@ func GetDatasourcesGetsBy(ctx *ctx.Context, typ, cate, name string, limit, offse session = session.Where("category = ?", cate) } + if status != "" { + session = session.Where("status = ?", status) + } + var lst []*Datasource - err := session.Order("id desc").Limit(limit).Offset(offset).Find(&lst).Error + err := session.Order("id desc").Find(&lst).Error if err == nil { for i := 0; i < len(lst); i++ { lst[i].DB2FE() diff --git a/prom/reader.go b/prom/reader.go index 9cb86153..8da72cc9 100644 --- a/prom/reader.go +++ b/prom/reader.go @@ -42,7 +42,7 @@ type PromSetting struct { } func (pc *PromClientMap) loadFromDatabase() { - datasources, err := models.GetDatasourcesGetsBy(pc.ctx, models.PROMETHEUS, "", "", 1000, 0) + datasources, err := models.GetDatasourcesGetsBy(pc.ctx, models.PROMETHEUS, "", "", "enabled") if err != nil { logger.Errorf("failed to get datasources, error: %v", err) return