Page MenuHomePhabricator

mw.Api.getMessages (and the methods that use it) should support loading more than 50 messages
Closed, ResolvedPublic

Description

Steps to reproduce:
Visit a wiki, open your javascript console, and run the following (assuming you don't have apihighlimits rights, if you do you'll need 501 messages to test with instead of 51)

// A collection of 51 different valid messages in MediaWiki
var missingMessages = [ "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sun", "mon", "tue", "wed", "thu", "fri", "sat", "january", "february", "march", "april", "may_long", "june", "july", "august", "september", "october", "november", "december", "january-gen", "february-gen", "march-gen", "april-gen", "may-gen", "june-gen", "july-gen", "august-gen", "september-gen", "october-gen", "november-gen", "december-gen", "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec", "january-date" ];
// Make sure that these are all indeed not yet loaded, using the same logic that mw.api.loadMessagesIfMissing does to check
missingMessages.filter( function ( msg ) { return !mw.message( msg ).exists(); } ).length === 51 // should be true
// Try to load
(new mw.Api()).loadMessagesIfMissing( missingMessages ).then(
    function () { console.log( 'loaded' ); },
    function () { console.log( 'Error', arguments ); }
);

Expected result: messages are loaded (at least the first 50)
Actual result: api failure with code toomanyvalues

Proposal: only retrieve 50 messages at a time, calling the method recursively if needed

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

Change 716086 had a related patch set uploaded (by DannyS712; author: DannyS712):

[mediawiki/core@master] mw.Api: only try to load 50 messages at a time

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

Krinkle renamed this task from mw.Api.getMessages (and the methods that use it) should handle too many messages to mw.Api.getMessages (and the methods that use it) should support loading more than 50 messages.Sep 2 2021, 7:01 PM

Change 716086 merged by jenkins-bot:

[mediawiki/core@master] mediawiki.api: Support loading more than 50 messages, through batching

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

I see the patch is already merged, but why not use concurrent API requests, rather than serial? Since mw.Api is used by user-facing code and fetch of messages is usually a blocker for the rest of the application to become interactive, I think it's justifiable to use parallel requests as that would be much faster.

I see the patch is already merged, but why not use concurrent API requests, rather than serial? Since mw.Api is used by user-facing code and fetch of messages is usually a blocker for the rest of the application to become interactive, I think it's justifiable to use parallel requests as that would be much faster.

I thought that would be adverse for performance, but if you want to file a separate task for that I wouldn't oppose the change