Stop a project being returned as a fork of itself
What does this MR do and why?
Restores forking for users whose only forkable namespace is their personal namespace. The Fork button on a project page now offers a new fork instead of linking back to the project the user is already on.
Problem
Currently on master, such a user cannot fork a project from its page once they have deleted their own fork of it, because the Fork button links back to that same page while the forks counter shows 0. A fork network keeps its root project as a member, and find_forks_in matches any network project in the namespace without excluding the one being asked about, so Namespace#find_fork_of can answer with that project itself. The same wrong answer sends "Go to your fork" to the source project while the fork still exists.
Review notes
- Why fix
find_fork_ofand notfind_forks_in?find_forks_inanswers which of the given projects are in the network, and the root is one of them.find_fork_ofanswers which project in this namespace is a fork of another, where the project is never a valid answer. - What do the query plans say? Only the subquery picking the candidate projects changes, by one
!=predicate. Locally it lands as a filter on the existing index-only scan overindex_projects_on_namespace_id_and_id, with the same plan shape and the same cost estimate, so no new index. I have no Database Lab access as an external contributor, so please confirm that against production-sized data. - What is left alone? A fork marked for deletion still counts, so the button points at the renamed
...-deletion_scheduled-<id>project. Same cause, but the user can still restore that project, which makes it a product question rather than a defect. Tracked at #369498 (closed).
References
- #629277 (closed) — the issue this MR closes, with a screen recording
- #329755 (closed) — same symptom in 2021, closed as stale
- #375555 (closed) — names the wide fork network search, closed as stale
- #422242 (closed) — same symptom, closed by the reporter, confirmed by a second user
Screenshots or screen recordings
| Before | After |
|---|---|
How to set up and validate locally
- Sign in as a user who belongs to no group that allows project creation.
- Create a public project in their personal namespace, then fork it into that same namespace.
- Delete the fork.
- Open the source project page. The Fork button links to
/-/forks/newinstead of back to the project.
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.