You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by ab...@apache.org on 2022/10/28 03:00:39 UTC

[incubator-devlake] branch release-v0.14 updated (ed32e1ad -> 586e0f3c)

This is an automated email from the ASF dual-hosted git repository.

abeizn pushed a change to branch release-v0.14
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


    from ed32e1ad fix: starrocks sync data type (#3576)
     new 822d7ab7 feat: the GetBlueprintPipelines interface support page/pagesize/status/pending params (#3597)
     new 586e0f3c fix(framework): add max pageSize (#3598)

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 api/blueprints/blueprints.go            | 14 +++++++++-----
 services/blueprint_helper.go            |  7 +++----
 services/{pushapi.go => page_helper.go} | 20 +++++++++++++-------
 services/pipeline_helper.go             |  7 +++----
 services/task.go                        |  7 +++----
 5 files changed, 31 insertions(+), 24 deletions(-)
 copy services/{pushapi.go => page_helper.go} (71%)


[incubator-devlake] 02/02: fix(framework): add max pageSize (#3598)

Posted by ab...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

abeizn pushed a commit to branch release-v0.14
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git

commit 586e0f3c849bb86eafd085833cea2fe6a87418dc
Author: Warren Chen <yi...@merico.dev>
AuthorDate: Fri Oct 28 10:05:31 2022 +0800

    fix(framework): add max pageSize (#3598)
    
    closes #3593
---
 services/blueprint_helper.go |  7 +++----
 services/page_helper.go      | 35 +++++++++++++++++++++++++++++++++++
 services/pipeline_helper.go  |  7 +++----
 services/task.go             |  7 +++----
 4 files changed, 44 insertions(+), 12 deletions(-)

diff --git a/services/blueprint_helper.go b/services/blueprint_helper.go
index 033dd068..393735ff 100644
--- a/services/blueprint_helper.go
+++ b/services/blueprint_helper.go
@@ -48,10 +48,9 @@ func GetDbBlueprints(query *BlueprintQuery) ([]*models.DbBlueprint, int64, error
 	if err != nil {
 		return nil, 0, errors.Default.Wrap(err, "error getting DB count of blueprints")
 	}
-	if query.Page > 0 && query.PageSize > 0 {
-		offset := query.PageSize * (query.Page - 1)
-		db = db.Limit(query.PageSize).Offset(offset)
-	}
+
+	db = processDbClausesWithPager(db, query.PageSize, query.Page)
+
 	err = db.Find(&dbBlueprints).Error
 	if err != nil {
 		return nil, 0, errors.Default.Wrap(err, "error finding DB blueprints")
diff --git a/services/page_helper.go b/services/page_helper.go
new file mode 100644
index 00000000..6c80705b
--- /dev/null
+++ b/services/page_helper.go
@@ -0,0 +1,35 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package services
+
+import "gorm.io/gorm"
+
+const maxPageSize = 100
+
+func processDbClausesWithPager(tx *gorm.DB, pageSize int, page int) *gorm.DB {
+	if pageSize <= 0 || pageSize > maxPageSize {
+		pageSize = maxPageSize
+	}
+	tx = tx.Limit(pageSize)
+
+	if page > 0 {
+		offset := pageSize * (page - 1)
+		tx = tx.Offset(offset)
+	}
+	return tx
+}
diff --git a/services/pipeline_helper.go b/services/pipeline_helper.go
index 203f475b..5019b4df 100644
--- a/services/pipeline_helper.go
+++ b/services/pipeline_helper.go
@@ -113,10 +113,9 @@ func GetDbPipelines(query *PipelineQuery) ([]*models.DbPipeline, int64, errors.E
 	if err != nil {
 		return nil, 0, errors.Default.Wrap(err, "error getting DB pipelines count")
 	}
-	if query.Page > 0 && query.PageSize > 0 {
-		offset := query.PageSize * (query.Page - 1)
-		db = db.Limit(query.PageSize).Offset(offset)
-	}
+
+	db = processDbClausesWithPager(db, query.PageSize, query.Page)
+
 	err = db.Find(&dbPipelines).Error
 	if err != nil {
 		return nil, count, errors.Default.Wrap(err, "error finding DB pipelines")
diff --git a/services/task.go b/services/task.go
index 43d41f1c..aa3739c5 100644
--- a/services/task.go
+++ b/services/task.go
@@ -182,10 +182,9 @@ func GetTasks(query *TaskQuery) ([]models.Task, int64, errors.Error) {
 	if err != nil {
 		return nil, 0, errors.Convert(err)
 	}
-	if query.Page > 0 && query.PageSize > 0 {
-		offset := query.PageSize * (query.Page - 1)
-		db = db.Limit(query.PageSize).Offset(offset)
-	}
+
+	db = processDbClausesWithPager(db, query.PageSize, query.Page)
+
 	tasks := make([]models.Task, 0)
 	err = db.Find(&tasks).Error
 	if err != nil {


[incubator-devlake] 01/02: feat: the GetBlueprintPipelines interface support page/pagesize/status/pending params (#3597)

Posted by ab...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

abeizn pushed a commit to branch release-v0.14
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git

commit 822d7ab74b91b7c435f0e79510edf3cfbbc12edc
Author: abeizn <zi...@merico.dev>
AuthorDate: Thu Oct 27 19:28:34 2022 +0800

    feat: the GetBlueprintPipelines interface support page/pagesize/status/pending params (#3597)
---
 api/blueprints/blueprints.go | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/api/blueprints/blueprints.go b/api/blueprints/blueprints.go
index 9bb9c25c..dd818815 100644
--- a/api/blueprints/blueprints.go
+++ b/api/blueprints/blueprints.go
@@ -212,14 +212,18 @@ func Trigger(c *gin.Context) {
 // @Failure 500  {string} errcode.Error "Internel Error"
 // @Router /blueprints/{blueprintId}/pipelines [get]
 func GetBlueprintPipelines(c *gin.Context) {
-	blueprintId := c.Param("blueprintId")
-	id, err := strconv.ParseUint(blueprintId, 10, 64)
+	var query services.PipelineQuery
+	err := c.ShouldBindQuery(&query)
+	if err != nil {
+		shared.ApiOutputError(c, errors.BadInput.Wrap(err, shared.BadRequestBody))
+		return
+	}
+	err = c.ShouldBindUri(&query)
 	if err != nil {
-		shared.ApiOutputError(c, errors.BadInput.Wrap(err, "bad blueprintID at supplied"))
+		shared.ApiOutputError(c, errors.BadInput.Wrap(err, "bad request URI format"))
 		return
 	}
-	var query services.PipelineQuery
-	query.BlueprintId = id
+
 	pipelines, count, err := services.GetPipelines(&query)
 	if err != nil {
 		shared.ApiOutputError(c, errors.Default.Wrap(err, "error getting pipelines"))