Page MenuHomePhabricator

Batch entity labels in formatted comments (history, recent changes, etc.)
Open, Needs TriagePublic

Description

In T285917, the formatting of comments in revision lists was batched in MediaWiki core, to reduce the amount of database queries. (Regular comments need to do database queries to check if [[links]] in comments are blue or red, if I understand correctly.) Wikibase likes to add labels to links to entities in comments (e.g. [[Property:P735]]: [[Q463035]]given name (P735): Douglas (Q463035)), and it would be great to batch this work as well, getting all the labels (and descriptions) in one go.

Currently, getting 500 history lines from Q42 makes 2816 DatabaseMysqli::doQuery() calls. See also T292203 for a semi-related task where (due to a bug) we try to format so many links that the request times out.

Event Timeline

Federated properties introduced prefetching for the things needed during formatting

https://github.com/wikimedia/Wikibase/blob/25c49a6fee0d78b241eaceeb7b91b232c8fe558a/repo/includes/Hooks/LabelPrefetchHookHandler.php#L129-L135

But this is not done for regular operation.
It would need some similar code.

AFAIK this code path should already go via the formatter cache etc (which complicated prefetching a little)
As we perhaps don't want to prefetch things that are already in the cache from the DB

@Addshore suggested that there might be some batching here already, added for federated properties. We should check why there are still so many unbatched database calls then.