[Backend] Add wiki pages to recently viewed items
What does this MR do and why?
- Adds wiki pages to the recently viewed items list
-
Tracks wiki page views: Logs when users view wiki pages by calling
log_wiki_page_viewin theWikiActionscontroller, storing the view in the user's recent items history -
Enables wiki page search in recent items: Creates
WikiPageMetaFinderto search wiki pages by title with case-insensitive partial matching, allowing users to find recently viewed wiki pages -
Integrates wiki pages into GraphQL API: Adds
WikiPage::Metaas a new type in theRecentlyViewedItemUnionGraphQL type, enabling frontend queries for recently viewed wiki pages alongside issues and merge requests - Adds wiki pages to autocomplete: Includes recently viewed wiki pages in the search autocomplete dropdown under "Recent wiki pages" category, making it easier to quickly navigate back to previously viewed wiki content
-
Implements permission checks: Ensures users can only see recently viewed wiki pages they have permission to read through
Ability.allowed?checks -
Follows existing patterns: Implements
RecentWikiPagesclass following the same structure asRecentIssuesandRecentMergeRequestsfor consistency - Note on future iteration: Discovered an issue where if the wiki page is deleted, it'll still show up in the recently viewed list (but redirect to the home page). Ideally we don't show deleted items in this list. Will look into this and address this in another MR as it's not a blocker.
Why: This improves user productivity by allowing quick access to recently viewed wiki pages through the same mechanisms already available for issues and merge requests, creating a more consistent navigation experience across GitLab.
Testing notes
Test ran locally via GDK with the FrontEnd changes.
- Default (empty) state of recently viewed items:
- Confirmed that newly created wiki page (visited) shows up:
- Confirmed that recently viewed MRs and Issues still show up:
- Note: currently if I delete said wiki page, it'll still show up in this section but redirect to the create a wiki page home page. Will mention this in the issue but likely not a blocker.
Database Review
These changes introduce two new queries via WikiPageMetaFinder and the new scopes in WikiPage::Meta.
Query Details
I. for_projects_visible_to_user
SELECT
"wiki_page_meta".*
FROM
"wiki_page_meta"
INNER JOIN "projects" ON "projects"."id" = "wiki_page_meta"."project_id"
WHERE (EXISTS (
SELECT
1
FROM
"project_authorizations"
WHERE
"project_authorizations"."user_id" = 1
AND (project_authorizations.project_id = projects.id))
OR projects.visibility_level IN (0, 10, 20))
AND "wiki_page_meta"."id" IN (3, 1)
ORDER BY
array_position(ARRAY[3, 1], wiki_page_meta.id)
LIMIT 5
- Query plan: https://postgres.ai/console/gitlab/gitlab-production-main/sessions/50009/commands/148618
II. Autocomplete search_by_title
SELECT
"wiki_page_meta".*
FROM
"wiki_page_meta"
INNER JOIN "projects" ON "projects"."id" = "wiki_page_meta"."project_id"
WHERE (EXISTS (
SELECT
1
FROM
"project_authorizations"
WHERE
"project_authorizations"."user_id" = 1
AND (project_authorizations.project_id = projects.id))
OR projects.visibility_level IN (0, 10, 20))
AND (wiki_page_meta.title ILIKE '%friday%')
AND "wiki_page_meta"."id" IN (3, 1)
ORDER BY
array_position(ARRAY[3, 1], wiki_page_meta.id)
LIMIT 5
- Query plan: https://postgres.ai/console/gitlab/gitlab-production-main/sessions/50009/commands/148619
In providing the above, I did my best to follow the guidance described in the docs. Please advise if anything needs to be updated, clarified, or added!
References
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Related to #592834


