Skip to content

Load mentionValues asynchronously#36739

Merged
lunny merged 27 commits intogo-gitea:mainfrom
silverwind:asyncmention
Mar 7, 2026
Merged

Load mentionValues asynchronously#36739
lunny merged 27 commits intogo-gitea:mainfrom
silverwind:asyncmention

Conversation

@silverwind
Copy link
Copy Markdown
Member

@silverwind silverwind commented Feb 24, 2026

Eliminate a few database queries on all issue and pull request pages by moving mention autocomplete data to async JSON endpoints fetched on-demand when the user types @.

See #36739 (comment) for the full table of affected pages.

🤖 Generated with Claude Code

Move mention autocomplete data (participants, assignees, teams) from
being embedded inline in every page's HTML to a dedicated JSON endpoint
that is fetched on-demand when the user triggers @ mention autocomplete.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Feb 24, 2026
@silverwind silverwind changed the title Load mentionValues asynchronously Load mentionValues asynchronously Feb 24, 2026
@github-actions github-actions bot added modifies/go Pull requests that update Go code modifies/templates This PR modifies the template files modifies/frontend labels Feb 24, 2026
@silverwind silverwind added the performance/speed performance issues with slow downs label Feb 24, 2026
@silverwind silverwind requested a review from Copilot February 24, 2026 14:06
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request improves performance by converting mentionValues from server-side template data to an asynchronous API fetch. This eliminates database queries on every issue/pull request page load, deferring the work until the user actually types @ to trigger mention autocomplete.

Changes:

  • Removed server-side mentionValues injection from templates and replaced it with a lazy-loading API endpoint
  • Updated frontend mention matching to fetch data asynchronously when needed
  • Refactored backend helper functions to support the new API endpoint

Reviewed changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
templates/base/head_script.tmpl Removed server-side mentionValues injection from global config
web_src/js/globals.d.ts Removed mentionValues from window.config TypeScript definition
web_src/js/vitest.setup.ts Removed test fixture mentionValues data
web_src/js/utils/match.ts Added fetchMentionValues function with caching and made matchMention async
web_src/js/utils/match.test.ts Updated tests to mock GET and handle async matchMention
web_src/js/features/tribute.ts Changed mentionCollection values to async callback using fetchMentionValues
web_src/js/features/comp/TextExpander.ts Wrapped mention handling in async IIFE to await matchMention
routers/web/web.go Registered new GET endpoint /-/mentionvalues
routers/web/repo/mention.go New endpoint handler returning JSON mention data (participants, assignees, teams)
routers/web/repo/issue.go Refactored handleMentionableAssigneesAndTeams to getMentionableTeams helper
routers/web/repo/issue_page_meta.go Simplified to only set Assignees data without calling mention handler
routers/web/repo/issue_list.go Simplified to only set Assignees data without calling mention handler
routers/web/repo/pull.go Simplified to only set Assignees data without calling mention handler

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@lunny
Copy link
Copy Markdown
Member

lunny commented Feb 25, 2026

Generally LGTM, it's better to have a better name for the router path and function name.

@silverwind
Copy link
Copy Markdown
Member Author

Yeah I will rename.

@silverwind
Copy link
Copy Markdown
Member Author

I will rename alle mentionValues to just mentions, e.g. removing the Value part.

…ntion.go

- Rename MentionValues -> GetMentions and route /mentionvalues -> /mentions
- Move getMentionableTeams from issue.go to mention.go
- Rename MentionValue type to Mention, fetchMentionValues to fetchMentions

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Require at least one markdown-capable unit (Code, Issues, PullRequests,
Releases, Wiki) read access to use the mentions autocomplete endpoint.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@silverwind silverwind marked this pull request as draft February 25, 2026 21:45
Replace reqUnitsWithMarkdown (which included TypeCode, making it
effectively a no-op) with a new reqUnitCommentWriter that requires
read access to at least one unit with markdown editors: Issues,
PullRequests, Releases, Wiki, or Projects.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@lunny
Copy link
Copy Markdown
Member

lunny commented Feb 26, 2026

image

@silverwind
Copy link
Copy Markdown
Member Author

silverwind commented Feb 26, 2026

Mentions do not work at all in the form for me on main branch, so this is new functionality.

@silverwind
Copy link
Copy Markdown
Member Author

silverwind commented Feb 26, 2026

Actually it does work for me now on this branch, odd. I can't see the full URL in your screenshot.

image

@silverwind
Copy link
Copy Markdown
Member Author

silverwind commented Feb 26, 2026

I think i can make it work for:

- /user/repo/projects/new
- /org/repo/projects/new
- /org/-/projects/new
- /user/-/projects/new
- /user/repo/projects/<id>/edit
- /org/repo/projects/<id>/edit
- /org/-/projects/<id>/edit
- /user/-/projects/<id>/edit

I don't think mentions worked on any of these pages before but we can fix it here I guess.

@silverwind
Copy link
Copy Markdown
Member Author

silverwind commented Feb 26, 2026

This comment was written by Claude.

Here's a summary of all pages with mention autocomplete and what values they display:

URL Endpoint Values
Issue / PR pages (repo context, with issue participants)
/{owner}/{repo}/issues/{index} /{owner}/{repo}/-/mentions?issue_index={index} participants, assignees, teams*
/{owner}/{repo}/pulls/{index} /{owner}/{repo}/-/mentions?issue_index={index} participants, assignees, teams*
/{owner}/{repo}/pulls/{index}/files /{owner}/{repo}/-/mentions?issue_index={index} participants, assignees, teams*
Repo pages (no issue context)
/{owner}/{repo}/issues/new /{owner}/{repo}/-/mentions assignees, teams*
/{owner}/{repo}/compare/{base}...{head} /{owner}/{repo}/-/mentions assignees, teams*
/{owner}/{repo}/milestones/new /{owner}/{repo}/-/mentions assignees, teams*
/{owner}/{repo}/milestones/{id}/edit /{owner}/{repo}/-/mentions assignees, teams*
/{owner}/{repo}/wiki/* /{owner}/{repo}/-/mentions assignees, teams*
/{owner}/{repo}/releases/new /{owner}/{repo}/-/mentions assignees, teams*
/{owner}/{repo}/releases/edit/{tag} /{owner}/{repo}/-/mentions assignees, teams*
/{user}/{repo}/projects/new /{user}/{repo}/-/mentions assignees
/{user}/{repo}/projects/{id}/edit /{user}/{repo}/-/mentions assignees
/{org}/{repo}/projects/new /{org}/{repo}/-/mentions assignees, teams*
/{org}/{repo}/projects/{id}/edit /{org}/{repo}/-/mentions assignees, teams*
Org/user pages (no repo context)
/{org}/-/projects/new /{org}/-/mentions org members, org teams
/{org}/-/projects/{id}/edit /{org}/-/mentions org members, org teams
/{user}/-/projects/new /{user}/-/mentions (empty)
/{user}/-/projects/{id}/edit /{user}/-/mentions (empty)

* org teams only shown when the repo owner is an organization

Add /{username}/-/mentions endpoint that returns org members and teams
for mention autocomplete on org-level project pages. Update the JS to
detect org vs repo context and call the appropriate endpoint.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@silverwind
Copy link
Copy Markdown
Member Author

@lunny try again, it should work on all 18 pages mentioned above.

Add ok: true to the mocked GET response so the res.ok check in
fetchMentions does not reject the response.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@lunny
Copy link
Copy Markdown
Member

lunny commented Feb 26, 2026

@lunny try again, it should work on all 18 pages mentioned above.

Works now. It seems wiki editor needs also to add @ and # icons(unrelated to this PR)

image

@wxiaoguang wxiaoguang marked this pull request as draft March 1, 2026 17:41
silverwind and others added 2 commits March 6, 2026 17:14
Instead of having the client parse window.location to construct the
mentions API URL, pass it from the server via a data-mentions-url
attribute on the combo-markdown-editor element. This addresses review
feedback that the framework should provide the URL rather than having
the client do URL parsing.

- Add MentionsUrl template attribute to combomarkdowneditor.tmpl
- Show @/# toolbar buttons only when MentionsUrl is set
- All template callers pass MentionsUrl from server context
- JS reads mentions URL from data attribute, no more URL parsing
- Cache the fetch promise to avoid race conditions
- Remove redundant MentionSuggestion type, use Mention directly
- Reuse parseIssuePageInfo() instead of inline DOM query

Co-Authored-By: Claude claude-opus-4-6 20250627 <noreply@anthropic.com>
@silverwind silverwind marked this pull request as ready for review March 6, 2026 17:06
@silverwind
Copy link
Copy Markdown
Member Author

Everything addressed and table in #36739 (comment) is up to date. All pages were tested.

This comment was marked as resolved.

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Mar 7, 2026
@lunny lunny merged commit 130e349 into go-gitea:main Mar 7, 2026
26 checks passed
@silverwind silverwind deleted the asyncmention branch March 8, 2026 06:23
silverwind added a commit to silverwind/gitea that referenced this pull request Mar 8, 2026
* origin/main:
  Optimize Docker build with dependency layer caching (go-gitea#36864)
  Fix URLJoin, markup render link reoslving, sign-in/up/linkaccount page common data (go-gitea#36861)
  Fix CodeQL code scanning alerts (go-gitea#36858)
  Refactor auth middleware (go-gitea#36848)
  Update Nix flake (go-gitea#36857)
  Update JS deps (go-gitea#36850)
  Load `mentionValues` asynchronously (go-gitea#36739)
  [skip ci] Updated translations via Crowdin
silverwind added a commit to silverwind/gitea that referenced this pull request Mar 8, 2026
* main: (26 commits)
  Clean up `refreshViewedFilesSummary` (go-gitea#36868)
  Remove `util.URLJoin` and replace all callers with direct path concatenation (go-gitea#36867)
  Optimize Docker build with dependency layer caching (go-gitea#36864)
  Fix URLJoin, markup render link reoslving, sign-in/up/linkaccount page common data (go-gitea#36861)
  Fix CodeQL code scanning alerts (go-gitea#36858)
  Refactor auth middleware (go-gitea#36848)
  Update Nix flake (go-gitea#36857)
  Update JS deps (go-gitea#36850)
  Load `mentionValues` asynchronously (go-gitea#36739)
  [skip ci] Updated translations via Crowdin
  Fix dbfs error handling (go-gitea#36844)
  Fix OAuth2 authorization code expiry and reuse handling (go-gitea#36797)
  Fix org permission API visibility checks for hidden members and private orgs (go-gitea#36798)
  Fix non-admins unable to automerge PRs from forks (go-gitea#36833)
  upgrade to github.com/cloudflare/circl 1.6.3, svgo 4.0.1, markdownlint-cli 0.48.0 (go-gitea#36837)
  Fix dump release asset bug (go-gitea#36799)
  build(deps): update material-icon-theme v5.32.0 (go-gitea#36832)
  Fix bug to check whether user can update pull request branch or rebase branch (go-gitea#36465)
  Fix forwarded proto handling for public URL detection (go-gitea#36810)
  Fix artifacts v4 backend upload problems (go-gitea#36805)
  ...

# Conflicts:
#	pnpm-lock.yaml
zjjhot added a commit to zjjhot/gitea that referenced this pull request Mar 10, 2026
* giteaofficial/main:
  Update minimum go version to 1.26.1, golangci-lint to 2.11.2, fix test style (go-gitea#36876)
  Add render cache for SVG icons (go-gitea#36863)
  Fix incorrect viewed files counter if reverted change was viewed (go-gitea#36819)
  [skip ci] Updated translations via Crowdin
  Clean up `refreshViewedFilesSummary` (go-gitea#36868)
  Remove `util.URLJoin` and replace all callers with direct path concatenation (go-gitea#36867)
  Optimize Docker build with dependency layer caching (go-gitea#36864)
  Fix URLJoin, markup render link reoslving, sign-in/up/linkaccount page common data (go-gitea#36861)
  Fix CodeQL code scanning alerts (go-gitea#36858)
  Refactor auth middleware (go-gitea#36848)
  Update Nix flake (go-gitea#36857)
  Update JS deps (go-gitea#36850)
  Load `mentionValues` asynchronously (go-gitea#36739)
  [skip ci] Updated translations via Crowdin
  Fix dbfs error handling (go-gitea#36844)
  Fix OAuth2 authorization code expiry and reuse handling (go-gitea#36797)
  Fix org permission API visibility checks for hidden members and private orgs (go-gitea#36798)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/frontend modifies/go Pull requests that update Go code modifies/templates This PR modifies the template files performance/speed performance issues with slow downs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants