Page MenuHomePhabricator

Scribunto should provide a bulk ifexists check
Closed, ResolvedPublicFeature

Description

Feature summary (what you would like to be able to do and where):

It is roughly the same level of expensiveness to check if multiple pages exist as checking a single page

I Propose new static method of mw.title, checkExists that takes an array of page names, and returns an associative array listing which ones exist and which dont.

This function should only increment the expensive parser count once + 1 times per X pages in a single call, since its much cheaper to do it this way (not sure what an appropriate value for X is. I think either 25 or 50 would be reasonable)

Use case(s) (list the steps that you performed to discover that problem, and describe the actual underlying problem which you want to solve. Do not describe only a solution):

When people need to look up if several pages exist at once, they can do so much more efficiently. This also allows to look up more pages without hitting the expensive func limit and not causing performance issues.

Benefits (why should this be implemented?):

Encourages bulk page existence lookups which should mildly improve page render time.

Event Timeline

+1 to the general idea of making LinkBatch functionality available, I think there are a number of places where module authors can batch to optimize templates, just like we do in MediaWiki.

I suggested to @Bawolff in person that the function should return an array of mw.title objects, so we can preload the other fields that LinkBatch provides, and it allows us to easily preload other fields in the future, if it turns out that authors want other things too besides existence.

Are there modules for which this would be useful? Rarely is it the case that you need more than one or two checks per template instance.

The initial discussion was around pages using <translate> on commons, where the translated version was using twice as many checks because it needed to check both english and whatever lang it was translated into.

I suspect there are other use cases, but may be in more specialized tasks.

Change #1079220 had a related patch set uploaded (by Brian Wolff; author: Brian Wolff):

[mediawiki/extensions/Scribunto@master] Add new method mw.title.bulkNew to batch lookup expensive title props

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

I highly support this proposal. It essentially solves T278629. Many wikis do suffer from the current limit of 500. The number of pages needing over 500 IFEXIST:s is low, but they exist and are important. Example: https://sv.wiktionary.org/wiki/Wiktionary:Balans_efter_spr%C3%A5k_och_ordklass

function should return an array of mw.title objects, so we can preload the other fields

exactly :-)

Any progress, given that a patch emerged over 3 months ago?

@Taylor: See the patch status in Gerrit which says "Merge Conflict", so please feel free to rebase but note that Scribunto has no assigned code stewards; for general info see also https://www.mediawiki.org/wiki/Gerrit/Code_review/Getting_reviews

Any progress, given that a patch emerged over 3 months ago?

There was some feedback on the patch that i haven't responded to. I don't have very much time to devote to this, I'll probably get to it eventually, but if someone wanted to take over the patch, I definitely wouldn't object.

Change #1079220 merged by jenkins-bot:

[mediawiki/extensions/Scribunto@master] Add new method mw.title.newBatch to batch lookup expensive title props

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

[I moved this back to "to-triage" on the user-notice work board, since this finally got merged I wanted to bring attention back to it. Hopefully that was the right thing to do].

I think this change is worthy of announcing in tech news in the "Updates for technical contributors" section, I would suggest something like:

  • Lua modules can now use the mw.title.newBatch function to look up the existence of up to 25 pages at once while only incrementing the expensive function count once.

Great thing, but sure it already works? The mediawiki.org has 1.45.0-wmf.20 (26e679c) 21:55, 22 September 2025, and answers Lua error in console input at line 7: attempt to call field 'newBatch' (a nil value).

Ammarpad subscribed.

Great thing, but sure it already works?

This is not yet deployed. It will be in 1.45.0-wmf.21. (T376564#11208211)

So, maybe this should me mentioned somehow in the manual.

So, maybe this should me mentioned somehow in the manual.

Its mentioned at the very top of the page.

Sorry, couldn't find the text "The mw.title.newBatch section should be ignored until the next week" anywhere in that page.

"This page documents the latest version of the Scribunto extension. Some features may not be deployed yet."

I see. Thank you. Let's hope I'm the only one in the world with the banner blindness.

Ammarpad assigned this task to Bawolff.