Page MenuHomePhabricator

Non-expensive mw.title.new().exists media existence check is needed
Closed, DeclinedPublic

Description

mw.title.new('Media:' .. image).exists calls to check only the existence of media files are very expensive. A single call takes about 5 ms, and if there are about 100 calls—which is a realistic count—then it takes half a second of Lua computing time. The main cause for these expensive calls seems to be the creation of the file object which is not needed in many cases.

At Wikivoyage we need images to present them on maps. That's why the images are mostly not shown in the article itself, and authors cannot easily check spelling errors for this reason. The check is to be done in the template or Lua scripts themselves.

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald TranscriptNov 3 2017, 5:42 AM

{{#ifexist:Media:}} is also expensive, there is no way to make it cheaper, because files needs to check on foreign wikis like Wikimedia Commons. The wikitext parser function should behaviour the same as the lua function to avoid replacing each other for no gain.

One solution would be to provide a way to check multi titles with one call (using a table/array) to reduce the time, but not the expensive call counter.

Anomie closed this task as Declined.Nov 3 2017, 1:31 PM
Anomie added a subscriber: Anomie.

You should probably look into why you're having to check the existence of hundreds of images on a single page. That seems excessive.

RolandUnger reopened this task as Open.Nov 3 2017, 3:00 PM

Maybe you cannot imagine why to check so many images. Maybe have a look to the embassies section in https://en.wikivoyage.org/wiki/Washington,_D.C. Each embassy is presented by a listing template which could contain an image which is to check because it is not presented in the article but shown on a map if coordinates are present. The missing presence of images in the article is also the cause that you will not see a failure message.

I think one cause if these expensive mw.title.new().exists calls is that the object file is created which needs a lot of information from a database which is not necessary in many cases.

Now we are looking for several ways to slash computing times. Sometimes we have a computing time of 4 seconds. Without other optimizations we would have computing times of about 30 s because of time-consuming wikidata calls.

Anomie closed this task as Declined.Nov 3 2017, 3:11 PM