Page MenuHomePhabricator

Make BacklinksCache a service
Open, Needs TriagePublic

Description

BacklinksCache is created per-title right now. Instead, it needs to become a service class, maybe \MediaWiki\Page\LinksLookup?

Additionally, the following methods in from the Title object can be moved there:

  • Title::getLinksTo
  • Title::getTemplateLinksTo
  • Title::getLinksFrom
  • Title::getTemplateLinksFrom
  • Title::getBrokenLinksFrom

During the refactoring, it seems like some methods can be merged together, e.g. Title::getLinksTo and BacklinksCache::getLinks seem to be doing exactly the same thing - getting an array of titles, linking to the provided title in various ways, with the Title-based one doing no caching.

We can also improve the API - passing in the table name seems wrong, it at the very least should be a class constant, or perhaps we should split it into separate methods, e.g. getRedirectsTo, getTemplateLinksTo, etc.

All methods should be converted to receiving/returning PageIdentity/LinkTarget/Iterator<PageIdentity> as appropriate (probably PageIdentity for the vast majority of methods).

New service and all its methods has to be covered by tests.

Perhaps the LinksLookup has to be an interface, with 2 implementations, CachedLinksLookup and DBLinksLookup, with the caching one being an adapter to the DB one. Not sure about that.

Event Timeline

Change 719568 had a related patch set uploaded (by TChin; author: Derick Alangi):

[mediawiki/core@master] Add BacklinkCacheFactory Service

https://gerrit.wikimedia.org/r/719568

Change 719568 merged by jenkins-bot:

[mediawiki/core@master] Add BacklinkCacheFactory Service

https://gerrit.wikimedia.org/r/719568

We can also improve the API - passing in the table name seems wrong, it at the very least should be a class constant [...]

It seems like passing the table name is so that extensions can check for custom tables via the BacklinkCacheGetConditions hook. Unsure how to make the API better while still allowing for that flexibility.