refactor(discussion/client): remove redundant "first" variable init
The fetch loop already assigns "first" on each iteration, so the initial assignment in the variables map is dead code. Remove it from both List and Search. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
81117364ba
commit
2b794ed992
1 changed files with 5 additions and 14 deletions
|
|
@ -11,6 +11,9 @@ import (
|
|||
"github.com/shurcooL/githubv4"
|
||||
)
|
||||
|
||||
// maxPageSize is the maximum number of items per page allowed by the GitHub GraphQL API.
|
||||
const maxPageSize = 100
|
||||
|
||||
type discussionClient struct {
|
||||
gql *api.Client
|
||||
}
|
||||
|
|
@ -171,15 +174,9 @@ func (c *discussionClient) List(repo ghrepo.Interface, filters ListFilters, afte
|
|||
}
|
||||
}
|
||||
|
||||
perPage := limit
|
||||
if perPage > 100 {
|
||||
perPage = 100
|
||||
}
|
||||
|
||||
variables := map[string]interface{}{
|
||||
"owner": githubv4.String(repo.RepoOwner()),
|
||||
"name": githubv4.String(repo.RepoName()),
|
||||
"first": githubv4.Int(perPage),
|
||||
"after": (*githubv4.String)(nil),
|
||||
"orderBy": githubv4.DiscussionOrder{Field: orderField, Direction: orderDir},
|
||||
"categoryId": (*githubv4.ID)(nil),
|
||||
|
|
@ -214,7 +211,7 @@ func (c *discussionClient) List(repo ghrepo.Interface, filters ListFilters, afte
|
|||
remaining := limit
|
||||
|
||||
for {
|
||||
variables["first"] = githubv4.Int(min(remaining, 100))
|
||||
variables["first"] = githubv4.Int(min(remaining, maxPageSize))
|
||||
if err := c.gql.Query(repo.RepoHost(), "DiscussionList", &query, variables); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -319,14 +316,8 @@ func (c *discussionClient) Search(repo ghrepo.Interface, filters SearchFilters,
|
|||
searchQuery += " " + filters.Keywords
|
||||
}
|
||||
|
||||
perPage := limit
|
||||
if perPage > 100 {
|
||||
perPage = 100
|
||||
}
|
||||
|
||||
variables := map[string]interface{}{
|
||||
"query": githubv4.String(searchQuery),
|
||||
"first": githubv4.Int(perPage),
|
||||
"after": (*githubv4.String)(nil),
|
||||
}
|
||||
if after != "" {
|
||||
|
|
@ -337,7 +328,7 @@ func (c *discussionClient) Search(repo ghrepo.Interface, filters SearchFilters,
|
|||
remaining := limit
|
||||
|
||||
for {
|
||||
variables["first"] = githubv4.Int(min(remaining, 100))
|
||||
variables["first"] = githubv4.Int(min(remaining, maxPageSize))
|
||||
if err := c.gql.Query(repo.RepoHost(), "DiscussionListSearch", &query, variables); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue