@@ -32,6 +32,11 @@ SOFTWARE. */
3232
3333using json = nlohmann::json;
3434
35+ namespace
36+ {
37+ constexpr int BATCH_SIZE = 10 ;
38+ }
39+
3540IssueUpdater::IssueUpdater (const ProgramOptions &programOptions, PostDownloader &downloader,
3641 const std::vector<std::string> &issues,
3742 std::string_view labelID, std::string &error)
@@ -40,12 +45,31 @@ IssueUpdater::IssueUpdater(const ProgramOptions &programOptions, PostDownloader
4045 , m_issues(issues)
4146 , m_labelID(labelID)
4247 , m_error(error)
48+ , m_hasNextBatch(m_issues.size() > 0)
4349{
4450 m_error.clear ();
4551}
4652
4753void IssueUpdater::run ()
4854{
55+ if (!hasNextBatch ())
56+ return ;
57+
58+ m_downloader.setFinishedHandler (beast::bind_front_handler (&IssueUpdater::onFinishedPage, this ));
59+
60+ json req;
61+ req[" query" ] = nextBatch ();
62+ m_downloader.setRequestBody (req.dump ());
63+
64+ m_downloader.run ();
65+ m_downloader.setFinishedHandler (FinishedHandler{});
66+ }
67+
68+ std::string IssueUpdater::nextBatch ()
69+ {
70+ if (!hasNextBatch ())
71+ return {};
72+
4973 // Sample QraphQL string for the mutation with one alias named 'issue0'
5074 // "mutation UpdateIssue { comment0: : addComment(input: {subjectId:\"ID\", body:\"COMMENT\"}) { clientMutationId }
5175 // label0: addLabelsToLabelable(input: {labelableId:\"ID\", labelIds:[\"ID\"]}) { clientMutationId }
@@ -58,7 +82,9 @@ void IssueUpdater::run()
5882 int counter = 0 ;
5983 std::ostringstream buffer;
6084 buffer << start;
61- for (const auto &issueID : m_issues) {
85+ for (; ((m_issuePos < m_issues.size ()) && (counter < BATCH_SIZE)); ++m_issuePos) {
86+ const auto &issueID = m_issues[m_issuePos];
87+
6288 if (!m_programOptions.comment .empty ())
6389 buffer << makeCommentAlias (counter, issueID);
6490
@@ -72,16 +98,17 @@ void IssueUpdater::run()
7298
7399 ++counter;
74100 }
75- buffer << end;
76101
77- m_downloader.setFinishedHandler (beast::bind_front_handler (&IssueUpdater::onFinishedPage, this ));
102+ if (m_issuePos == m_issues.size ())
103+ m_hasNextBatch = false ;
78104
79- json req ;
80- req[ " query " ] = buffer.str ();
81- m_downloader. setRequestBody (req. dump ());
105+ buffer << end ;
106+ return buffer.str ();
107+ }
82108
83- m_downloader.run ();
84- m_downloader.setFinishedHandler (FinishedHandler{});
109+ bool IssueUpdater::hasNextBatch ()
110+ {
111+ return m_hasNextBatch;
85112}
86113
87114void IssueUpdater::onFinishedPage ()
@@ -97,6 +124,14 @@ void IssueUpdater::onFinishedPage()
97124 }
98125
99126 checkResponse (m_downloader.response ().body ());
127+
128+ if (!m_error.empty () || !hasNextBatch ())
129+ return ;
130+
131+ json req;
132+ req[" query" ] = nextBatch ();
133+ m_downloader.setRequestBody (req.dump ());
134+ m_downloader.sendRequest ();
100135}
101136
102137void IssueUpdater::checkResponse (std::string_view response)
0 commit comments