Feature summary
Following discussions at https://gerrit.wikimedia.org/r/c/mediawiki/core/+/1153983 with @Pppery and @matmarex, this proposal requests the implementation of an internal service (e.g., a “redirect target store”) designed to accept an array of page titles (up to a size of at least n=200) and perform batch processing to resolve redirect targets. For each provided title, the service should:
- Determine if the page is a redirect (i.e., its content includes a #REDIRECT directive).
- If it is a redirect, fetch and return the canonical redirect target title.
- If not a redirect, return null (or equivalent to indicate no redirect).
This batch-oriented method would replace repeated single-page queries, enabling more efficient querying by leveraging internal caching layers and optimized database access patterns.
Technical rationale and benefits
- Addressing performance bottlenecks with batch SQL queries Current redirect resolution in methods such as getRedirectTarget() executes an individual SQL query for each page to look up redirect targets. This causes severe performance degradation especially when processing large category pages or maintenance tasks, making these views slow (on the order of seconds or more). By designing a batch query mechanism to fetch redirect targets for multiple pages in a single SQL query, the load can be substantially reduced, improving page load times and server resource utilization.
- No existing batch redirect lookup in RedirectStore The current RedirectStore class implements target lookups only on a per-page basis. Implementing a dedicated batch API or service for redirect resolution requires significant design and development effort, but is necessary for scalability. Such a service would centralize and optimize redirect target fetches and prevent the repetitive querying inefficiency currently observed.
- Special pages and use cases Special pages like [[Special:DoubleRedirects]] and [[Special:BrokenRedirects]] also face this issue, as they perform redirect target lookups per page, leading to large numbers of queries and slow processing. Furthermore, this service will enable efficient implementation of task [T378683] (Show targets of redirects in categories), which currently suffers from performance issues due to lack of batch redirect target resolution. Introducing a batch redirect store would benefit these cases by reducing query overhead and improving responsiveness of maintenance operations and navigation-related features.
- Related optimizations for link existence checks Additional related inefficiencies exist, e.g., Linker::link() performs separate queries for each link target to determine existence (colouring links blue/red). These have been addressed elsewhere using batch lookups with classes like LinkBatch. Implementing similar batching for redirect lookups would align with this overall pattern of query optimization in MediaWiki.
