Skip to content

/repos/issue/search API is broken #10690

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
davydov-vyacheslav opened this issue Mar 10, 2020 · 17 comments · Fixed by #11696
Closed

/repos/issue/search API is broken #10690

davydov-vyacheslav opened this issue Mar 10, 2020 · 17 comments · Fixed by #11696
Labels
issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented type/bug
Milestone

Comments

@davydov-vyacheslav
Copy link

I'm trying to get list of all open PR within the system via API. When I'm trying to execute /repos/issue/search API request (even without search parameters, even without authentication -- just curl -X GET "https://try.gitea.io/api/v1/repos/issues/search") I'm retrieving the following error: Find: too many SQL variables

  • Gitea version: 1.12.0+dev-3-g9269b7f62
  • full request:curl -X GET "https://try.gitea.io/api/v1/repos/issues/search?state=open&type=pulls" -H "accept: application/json" -H "authorization: Basic ZGF2c0BqYXZhbml4LmNvbTpkYXZ5ZG92dnY="

P.S. I have local system of 1.11.2 version and don't have such issue.

@lunny lunny added the type/bug label Mar 10, 2020
@lunny lunny added this to the 1.12.0 milestone Mar 10, 2020
@jolheiser
Copy link
Member

Underlying SQL problem is related to #7750 and #9841

@stale
Copy link

stale bot commented May 9, 2020

This issue has been automatically marked as stale because it has not had recent activity. I am here to help clear issues left open even if solved or waiting for more insight. This issue will be closed if no further activity occurs during the next 2 weeks. If the issue is still valid just add a comment to keep it alive. Thank you for your contributions.

@stale stale bot added the issue/stale label May 9, 2020
@davydov-vyacheslav
Copy link
Author

unstale please

@stale stale bot removed the issue/stale label May 9, 2020
@lunny lunny added the issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented label May 17, 2020
@6543
Copy link
Member

6543 commented May 27, 2020

Does it still happen?

@a1012112796
Copy link
Member

Does it still happen?

image

@zeripath
Copy link
Contributor

The problem is this:

	for page := 1; ; page++ {
		opts.Page = page
		repos, count, err := models.SearchRepositoryByName(opts)
		if err != nil {
			ctx.Error(http.StatusInternalServerError, "SearchRepositoryByName", err)
			return
		}

		if len(repos) == 0 {
			break
		}
		log.Trace("Processing next %d repos of %d", len(repos), count)
		for _, repo := range repos {
			switch isClosed {
			case util.OptionalBoolTrue:
				issueCount += repo.NumClosedIssues
			case util.OptionalBoolFalse:
				issueCount += repo.NumOpenIssues
			case util.OptionalBoolNone:
				issueCount += repo.NumIssues
			}
			repoIDs = append(repoIDs, repo.ID)
		}
	}

This extracts all of the repo IDs that the search options could have found - I.e. Every repo that the user has access to... (Even worse than that it actually extracts all the repos out of the db.)

then:

	if len(keyword) > 0 && len(repoIDs) > 0 {
		issueIDs, err = issue_indexer.SearchIssuesByKeyword(repoIDs, keyword)
	}

plugs them all back in to a single SQL query.

On a big site like try there are likely easily >900 repos that a user could see - SQLite limits the number of variables to 999.

We shouldn't be doing it this way

@6543
Copy link
Member

6543 commented May 28, 2020

@zeripath we could replace repoIDs with a xorm.builder query witch we can join within SearchIssuesByKeyword as we have already done elsewhere

@zeripath
Copy link
Contributor

Exactly

@6543
Copy link
Member

6543 commented May 28, 2020

are you going for it?

@zeripath
Copy link
Contributor

Or should I say: genau

@zeripath
Copy link
Contributor

Nope I've played enough with reposearch recently - if I touch it again 🔥 may ensue

@6543
Copy link
Member

6543 commented May 28, 2020

haha - OK I'll give it a try

@zeripath
Copy link
Contributor

Remember whatever you do it needs a backport...

@6543
Copy link
Member

6543 commented May 28, 2020

😓

@6543
Copy link
Member

6543 commented May 28, 2020

ok the sittuation is worse than i thought

@zeripath
Copy link
Contributor

Now you see why I only commented and didn't fix ...

@6543
Copy link
Member

6543 commented May 28, 2020

@zeripath we could replace repoIDs with a xorm.builder query witch we can join within SearchIssuesByKeyword as we have already done elsewhere

this is not posible as it use the Indexer and the whole Indexer would need arewrite/refactory
so #11664 split In query up into multible one combinde by OR

@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented type/bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants