Page MenuHomePhabricator

jqueryMsg uses the same astCache for all parser objects
Closed, ResolvedPublic

Description

Oh man, this was annoying to discover…

jqueryMsg uses the same astCache for all parser objects. This is apparently expected behavior, but I'm pretty sure it's incorrect, as each parser can have different messages under the same key.

	mw.jqueryMsg.parser.prototype = {
		...
		 * This cache is shared by all instances of mw.jqueryMsg.parser.
		astCache: {},
		...
	}

Details

Reference
bz52042
Related Gerrit Patches:

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 22 2014, 1:47 AM
bzimport added a project: MediaWiki-JavaScript.
bzimport set Reference to bz52042.
bzimport added a subscriber: Unknown Object (MLST).
matmarex created this task.Jul 25 2013, 6:32 PM

neilk wrote:

Seems like this would be easy to fix, just create astCache as a property upon initialization.

Seems to have been a bug since the beginning (sorry), but the fact that there's a comment makes me think that maybe someone has deliberately preserved this behavior now. I can't think of any situation where you want multiple instances to share a cache, is there?

If you need multiple newly-created objects to share a cache, write a singleton to wrap this class. Kind of an antipattern IMO but whatever.

I added the comment after I also discovered it the hard way. If it's desired behavior to allow different messages with the same key, I agree it needs to change. It would use more memory, but simplify things. I think this has come up for me when writing unit tests.

If this change is made, onlyCurlyBraceTransform can also be removed from the AST key, since that is a per-parser setting.

matmarex updated the task description. (Show Details)May 10 2015, 9:47 PM
matmarex edited projects, added Technical-Debt; removed I18n.
matmarex set Security to None.
matmarex removed a subscriber: Unknown Object (MLST).

Change 246940 had a related patch set uploaded (by Bartosz Dziewoński):
mediawiki.jqueryMsg: Remove 'astCache'

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

Restricted Application added a subscriber: Aklapper. · View Herald TranscriptOct 16 2015, 8:18 PM
Krinkle closed this task as Resolved.Oct 27 2015, 4:47 AM
Krinkle claimed this task.

Change 246940 merged by jenkins-bot:
mediawiki.jqueryMsg: Remove 'astCache'

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

Change 249133 had a related patch set uploaded (by Bartosz Dziewoński):
mediawiki.jqueryMsg: Remove 'astCache'

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

Change 249133 merged by jenkins-bot:
mediawiki.jqueryMsg: Remove 'astCache'

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