You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by "likyh (via GitHub)" <gi...@apache.org> on 2023/02/03 10:27:29 UTC

[GitHub] [incubator-devlake] likyh opened a new pull request, #4320: feat: add PageInOrder to support request pages one by one

likyh opened a new pull request, #4320:
URL: https://github.com/apache/incubator-devlake/pull/4320

   ### Summary
   add PageInOrder to support request pages one by one.
   
   ### Does this close any open issues?
   Related to #4292
   
   ### Screenshots
   
   add test code in collector:
   ```golang
   	collector, err := helper.NewApiCollector(helper.ApiCollectorArgs{
   		……
   		PageSize:           50,
   		PageInOrder:        true,
   		Query: func(reqData *helper.RequestData) (url.Values, errors.Error) {
   			query := url.Values{}
   			query.Set("state", "all")
   			query.Set("pagelen", fmt.Sprintf("%v", reqData.Pager.Size))
   			if reqData.PrevPageResponse != nil {
   				resBody, err := io.ReadAll(reqData.PrevPageResponse.Body)
   				// decode json
   				u, err := url.Parse(rawMessages.Next)
   				query.Set("page", u.Query()[`page`][0])
   			}
   			return query, nil
   		},
   	})
   ```
   
   
   ```
   time="2023-02-03 18:09:51" level=info msg=" [collectApiPullRequestCommits] start api collection"
   time="2023-02-03 18:09:52" level=info msg=" [collectApiPullRequestCommits] finished records: 1"
   
   # the first number means the page
   # the second json means which pr is
   # the third number means what the next page token is
   1 {"BitbucketId":1} xGCox
   1 {"BitbucketId":3}
   1 {"BitbucketId":2} xGCox
   2 {"BitbucketId":1} 7nSyG
   2 {"BitbucketId":2} 7nSyG
   3 {"BitbucketId":1} LRCkr
   3 {"BitbucketId":2} LRCkr
   4 {"BitbucketId":1} RaSbR
   4 {"BitbucketId":2} RaSbR
   time="2023-02-03 18:09:55" level=info msg=" [collectApiPullRequestCommits] finished records: 10"
   5 {"BitbucketId":1}
   5 {"BitbucketId":2}
   time="2023-02-03 18:09:56" level=info msg=" [collectApiPullRequestCommits] end api collection without error"
   time="2023-02-03 18:09:56" level=info msg="finished step: 5 / 5"
   ```
   
   We can find 3 pr's commits are collected parallelly and each page in a PR are collected in order.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] klesh merged pull request #4320: feat: add GetNextPageCustomData to support request pages one by one

Posted by "klesh (via GitHub)" <gi...@apache.org>.
klesh merged PR #4320:
URL: https://github.com/apache/incubator-devlake/pull/4320


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] likyh commented on a diff in pull request #4320: feat: add GetNextPageCustomData to support request pages one by one

Posted by "likyh (via GitHub)" <gi...@apache.org>.
likyh commented on code in PR #4320:
URL: https://github.com/apache/incubator-devlake/pull/4320#discussion_r1095705528


##########
backend/helpers/pluginhelper/api/api_collector.go:
##########
@@ -208,13 +212,43 @@ func (collector *ApiCollector) exec(input interface{}) {
 	}
 	if collector.args.PageSize <= 0 {
 		collector.fetchAsync(reqData, nil)
+	} else if collector.args.PageInOrder {

Review Comment:
   add `GetNextPageCustomData` on par with `GetTotalPages`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] klesh commented on a diff in pull request #4320: feat: add PageInOrder to support request pages one by one

Posted by "klesh (via GitHub)" <gi...@apache.org>.
klesh commented on code in PR #4320:
URL: https://github.com/apache/incubator-devlake/pull/4320#discussion_r1095659740


##########
backend/helpers/pluginhelper/api/api_collector.go:
##########
@@ -208,13 +212,43 @@ func (collector *ApiCollector) exec(input interface{}) {
 	}
 	if collector.args.PageSize <= 0 {
 		collector.fetchAsync(reqData, nil)
+	} else if collector.args.PageInOrder {
+		collector.fetchPagesInOrder(reqData)
 	} else if collector.args.GetTotalPages != nil {
 		collector.fetchPagesDetermined(reqData)
 	} else {
 		collector.fetchPagesUndetermined(reqData)
 	}
 }
 
+// fetchPagesInOrder fetches data of all pages in order to build query by prev response
+func (collector *ApiCollector) fetchPagesInOrder(reqData *RequestData) {

Review Comment:
   How about `fetchPagesSequentially`?



##########
backend/helpers/pluginhelper/api/api_collector.go:
##########
@@ -208,13 +212,43 @@ func (collector *ApiCollector) exec(input interface{}) {
 	}
 	if collector.args.PageSize <= 0 {
 		collector.fetchAsync(reqData, nil)
+	} else if collector.args.PageInOrder {

Review Comment:
   I think we may define a `GetNextPagerUrl` function on par with `GetTotalPages`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] likyh commented on a diff in pull request #4320: feat: add GetNextPageCustomData to support request pages one by one

Posted by "likyh (via GitHub)" <gi...@apache.org>.
likyh commented on code in PR #4320:
URL: https://github.com/apache/incubator-devlake/pull/4320#discussion_r1095704244


##########
backend/helpers/pluginhelper/api/api_collector.go:
##########
@@ -208,13 +212,43 @@ func (collector *ApiCollector) exec(input interface{}) {
 	}
 	if collector.args.PageSize <= 0 {
 		collector.fetchAsync(reqData, nil)
+	} else if collector.args.PageInOrder {
+		collector.fetchPagesInOrder(reqData)
 	} else if collector.args.GetTotalPages != nil {
 		collector.fetchPagesDetermined(reqData)
 	} else {
 		collector.fetchPagesUndetermined(reqData)
 	}
 }
 
+// fetchPagesInOrder fetches data of all pages in order to build query by prev response
+func (collector *ApiCollector) fetchPagesInOrder(reqData *RequestData) {

Review Comment:
   fixed
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org