Skip to content
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

Allow searching issues by ID #31479

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

silkentrance
Copy link

@silkentrance silkentrance commented Jun 24, 2024

When you are entering a number in the issue search, you likely want the issue with the given ID (code internal concept: issue index).
As such, when a number is detected, the issue with the corresponding ID will now be added to the results.

Fixes #4479

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jun 24, 2024
@pull-request-size pull-request-size bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jun 24, 2024
@github-actions github-actions bot added the modifies/go Pull requests that update Go code label Jun 24, 2024
@silkentrance silkentrance force-pushed the fix/gh4479-issue-dependency-select-broken branch 2 times, most recently from 2e7aa6c to 7bfe539 Compare June 24, 2024 19:13
@delvh
Copy link
Member

delvh commented Jun 24, 2024

Erm… It looks like you mixed up concepts if I see that correctly:
An issue ID is instance-wide unique and never shown in the UI. You can only retrieve it from the API.
The issue index on the other hand is unique per repository and probably what you intended as that's what you can call as …/issues/2 for example.
But I do understand the confusion, if I didn't know about the underlying data model, I would have called it id as well.

@wxiaoguang
Copy link
Contributor

Actually I have a different idea for fixing the problem.

If an number is inputed, I think we should just query it directly from database and fill the result into the list.

Then everything works well and it doesn't need to depend on the indexer, and we could make the match issue at the top as the first one (it really helps for end users to quickly select it)

@silkentrance
Copy link
Author

silkentrance commented Jun 25, 2024

Erm… It looks like you mixed up concepts if I see that correctly: An issue ID is instance-wide unique and never shown in the UI. You can only retrieve it from the API. The issue index on the other hand is unique per repository and probably what you intended as that's what you can call as …/issues/2 for example. But I do understand the confusion, if I didn't know about the underlying data model, I would have called it id as well.

Oh, yes, currently they are in sync on my system 😄

I will fix that and also change it so that it will go the fast route via the index and db indexer. @wxiaoguang @delvh

@silkentrance silkentrance force-pushed the fix/gh4479-issue-dependency-select-broken branch from 7bfe539 to ba448d2 Compare June 25, 2024 17:43
@pull-request-size pull-request-size bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 25, 2024
@silkentrance
Copy link
Author

I need to wrap my head around the tests first but I think that it will be rather easy to do.

@silkentrance silkentrance force-pushed the fix/gh4479-issue-dependency-select-broken branch from ba448d2 to 604c69e Compare June 25, 2024 18:32
@pull-request-size pull-request-size bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 25, 2024
@silkentrance silkentrance force-pushed the fix/gh4479-issue-dependency-select-broken branch 4 times, most recently from 75361d4 to 51149a0 Compare June 25, 2024 19:17
@silkentrance
Copy link
Author

silkentrance commented Jun 25, 2024

I am at a loss here. While it compiles, lints and works just fine, the tests fail with some error message that I cannot figure out.

https://github.com/go-gitea/gitea/actions/runs/9668323949/job/26672235178?pr=31479#step:8:185

I noticed that the web route for the issue search will query for the repository ids that are accessible by the user, so I added the repository ids to the test cases as well, reasoning that passing in an empty array would be the cause, but it wasn't.

https://github.com/go-gitea/gitea/pull/31479/files#diff-da412f571b8d5ab9187ee252f9a0e71f0908915eec4bfd51ea584fd209b22ccdR91

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Jun 26, 2024

Hmm, maybe we could try a simpler approach (avoid touching too many if):

  1. Existing code keeps as-is
  2. Insert a new if: if input is number { query exactly one issue from db and insert into result list at the beginning }
  3. De-duplicate the result list

2 and 3 could be merged into one new function.

Then we only need to add a new function, it's easier to test and no need to handle various indexer cases. Then we only need to test the newly added function by some mocked data, no need to touch existing search indexer cases.

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Jun 26, 2024

If you don't mind, I could work on this PR and make some edits

@silkentrance silkentrance changed the title WIP Add issue/pull id to search WIP Add issue/pull index to search Jun 26, 2024
@silkentrance
Copy link
Author

Hmm, maybe we could try a simpler approach (avoid touching too many if):

  1. Existing code keeps as-is
  2. Insert a new if: if input is number { query exactly one issue from db and insert into result list at the beginning }
  3. De-duplicate the result list

2 and 3 could be merged into one new function.

Then we only need to add a new function, it's easier to test and no need to handle various indexer cases. Then we only need to test the newly added function by some mocked data, no need to touch existing search indexer cases.

This would break current behaviour, as the search is across all repositories that the user has access to, so searching for an issue by keyword will bring up issues from both repository a and b. And so must the search for the index number.

As for the failing test: like I said i must first get my head around the way that the test suite works incl. also the library being used...

@wxiaoguang
Copy link
Contributor

Sorry but maybe I haven't fully understand the problem. Could the "dependency dropdown" add other repository's issue as a dependency? IIRC it only support adding current repository's issues?

@silkentrance
Copy link
Author

silkentrance commented Jun 26, 2024

@wxiaoguang Found it, it is the sql query that included a query for index, which is actually a keyword in sqlite. My oh my, without any stracktraces available, this was hard to find 😁
But doing some googling for syntax error near index did the trick...

Shouldn't xorm take care of that? I have used the universal(?) escape using double quotes, e.g. "\"index\"", so this should work with all supported RDMBS. Or is there a better way to do it?
Maybe consider migrating issue.index to some other name that does not collide with a keyword from any of the supported RDBMS?
E.g. lid for local id or even rlid for repo local id.

@silkentrance
Copy link
Author

silkentrance commented Jun 26, 2024

Sorry but maybe I haven't fully understand the problem. Could the "dependency dropdown" add other repository's issue as a dependency? IIRC it only support adding current repository's issues?

Not with the version I am currently working on. It will give me results from multiple repositories I am the owner of. Not so shure, whether this applies to non admin/owner users...

But looking at the code at https://github.com/coldrye-collaboration/gitea/blob/fix/gh4479-issue-dependency-select-broken/routers/web/repo/issue.go#L2600, it seems as if it fetches all repositories that are accessible to the user.
See also https://github.com/coldrye-collaboration/gitea/blob/fix/gh4479-issue-dependency-select-broken/routers/web/repo/issue.go#L2549.

@silkentrance silkentrance force-pushed the fix/gh4479-issue-dependency-select-broken branch from 51149a0 to be7db18 Compare June 26, 2024 18:27
@silkentrance
Copy link
Author

silkentrance commented Jun 26, 2024

Hmm, maybe we could try a simpler approach (avoid touching too many if):

  1. Existing code keeps as-is
  2. Insert a new if: if input is number { query exactly one issue from db and insert into result list at the beginning }
  3. De-duplicate the result list

2 and 3 could be merged into one new function.

Then we only need to add a new function, it's easier to test and no need to handle various indexer cases. Then we only need to test the newly added function by some mocked data, no need to touch existing search indexer cases.

If you are worried about the cyclomatic complexity, be assured, that the new code is not a hotspot 😀

I think that keeping the SearchOptions.Index an optional and populating that optional in the root indexer should be kept, allowing you the possibility to use the indexers in case that a prefix based search on the index number is required.
This, of course can also be achieved with the db indexer, however, "casting" the index number into a string and then doing a like search on it is rather expensive.

For now, the optimal route will be taken via the db indexer.

@silkentrance
Copy link
Author

silkentrance commented Jun 26, 2024

@wxiaoguang And yes, tests are still failing because the order of the issue ids is always different, working on that.

The web route uses SortByCreatedDesc, so it is not random, but it might change in the future.
For now, I just rearranged the order as this is also the case with the other test cases.

@silkentrance silkentrance force-pushed the fix/gh4479-issue-dependency-select-broken branch from be7db18 to ef44af2 Compare June 26, 2024 19:10
@silkentrance silkentrance changed the title WIP Add issue/pull index to search Add issue/pull index to search Jun 26, 2024
@silkentrance
Copy link
Author

silkentrance commented Jun 26, 2024

@wxiaoguang I think that everything is working now and that the code is minimally intrusive. I am not liking the index thing, though and strongly believe that the issue.index should be renamed as xorm is not taking care of escaping the reserved keyword. And I am not so sure whether the elephants in the room, namely mssql or oracledb will support the double quote escape. Not so sure about mysql/mariadb, either.

@silkentrance
Copy link
Author

@wxiaoguang applied. thanks.

@silkentrance silkentrance force-pushed the fix/gh4479-issue-dependency-select-broken branch from c6972bb to e546736 Compare June 26, 2024 19:59
modules/indexer/issues/db/db.go Outdated Show resolved Hide resolved
modules/indexer/issues/internal/model.go Outdated Show resolved Hide resolved
@silkentrance silkentrance force-pushed the fix/gh4479-issue-dependency-select-broken branch 2 times, most recently from 91f3344 to 09a846f Compare June 28, 2024 19:55
@delvh delvh changed the title Add issue/pull index to search Include the issue with the given index in the search results when searching for numbers Jun 28, 2024
@delvh delvh changed the title Include the issue with the given index in the search results when searching for numbers Include issue ID in the search results Jun 28, 2024
@delvh delvh changed the title Include issue ID in the search results Allow searching issues by ID Jun 28, 2024
@delvh delvh added the type/enhancement An improvement of existing functionality label Jun 28, 2024
@silkentrance silkentrance force-pushed the fix/gh4479-issue-dependency-select-broken branch 2 times, most recently from 64750fd to 488e0db Compare June 29, 2024 11:40
- Use backticks instead of double quotes

Co-authored-by: wxiaoguang <[email protected]>
@silkentrance silkentrance force-pushed the fix/gh4479-issue-dependency-select-broken branch from 488e0db to 9c464e2 Compare June 29, 2024 11:46
@silkentrance
Copy link
Author

I have squashed the changes into a single commit.

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jun 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/need 1 This PR needs approval from one additional maintainer to be merged. modifies/go Pull requests that update Go code size/M Denotes a PR that changes 30-99 lines, ignoring generated files. type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Issue dependencies ui kind of broken
4 participants