Commit graph

38 commits

Author SHA1 Message Date
Tim Starling
8a010024be Optimise MessageCache::isMainCacheable() for the single-message case
Loading all messages with getSubitemList() takes about 10ms per
language and loads an array with ~20k elements. When messages in many
languages are requested, this causes an OOM.

So, use getSubitemList() only when isMainCacheable() is called from
loadFromDB(). Remove the second parameter in that case, since it was
always the same.

In the getMsgFromNamespace() case, use getSubitem() to check the
specific message for existence. Have the caller specify the language, in
order to share a subitem cache entry with usual previous
getMessageForLang() call.

Bug: T247223
Change-Id: I6369f307b6bf74bd4aeb1d6e4c41d6e59e403703
2021-05-12 14:19:59 +10:00
James D. Forrester
df5eb22f83 Replace uses of DB_MASTER with DB_PRIMARY
Just an auto-replace from codesniffer for now.

Change-Id: I5240dc9ac5929d291b0ef1c743ea2bfd3f428266
2021-04-29 09:24:31 -07:00
daniel
7ffacacc6b MCR import
Bug: T220525
Change-Id: I7d41a8af12e33aed802526eb39a0880292c4f534
2020-07-18 20:34:16 -04:00
DannyS712
d349b03db9 Make MessageCacheTest::makePage private, return RevisionRecord
Replace WikiPage::doEditContent with PageUpdater

Bug: T249393
Bug: T250638
Change-Id: I69bfe2c8e47a75171584fd0a984a4f37f88a3d4b
2020-05-21 03:25:05 +00:00
Timo Tijhof
c036b6aa5b cache: Remove use of $wgContLanguageCode in MessageCacheTest
Has been an unconfigurable copy of $wgLanguageCode,
since 2006 (MW 1.8).

Bug: T247674
Change-Id: I35f03bfcbf416d8689ba7b42c2bc4b9b0f1376e3
2020-03-15 00:23:02 +00:00
Umherirrender
3161311c5a Use MediaWikiServices::getMessageCache
Change-Id: I07fcc9529991adc634c10e5ed8498ac138a1c2b7
2020-03-14 14:25:03 +01:00
Max Semenik
48a323f702 tests: Add explicit return type void to setUp() and tearDown()
Bug: T192167
Depends-On: I581e54278ac5da3f4e399e33f2c7ad468bae6b43
Change-Id: I3a21fb55db76bac51afdd399cf40ed0760e4f343
2019-10-30 14:31:22 -07:00
Umherirrender
5bd311b1a2 Add public as visibility in tests folder
Add public, protected or private to function missing a visibility
Enable the tests folder for the phpcs sniff

Change-Id: Ibefce76ea9984c47e08c94889ea2eafca7565e2c
2019-10-10 21:55:37 +02:00
Thiemo Kreuz
32a429e8c4 tests: Prefer assertSame() when comparing the integer 0
assertSame() is guaranteed to not do any type conversion. This can be
critical when acciden tially comparing, for example, 0 to 0.0.

Change-Id: Iffcc9bda69573623ba14af655dcd697d0fcce525
2019-09-19 15:35:23 +00:00
Aryeh Gregor
7fb4a95563 Remove unneeded overrideMwServices/resetServices
Change-Id: If6cbdec05b8f310ef3a0b4649aaa16d9fb80a047
2019-08-29 14:26:18 +03:00
Aryeh Gregor
752e7dd707 Convert MessageCache to service
Depends-On: Ia70e6c75f6e8a533f20cd44ebb05e013678e9951
Depends-On: I546eda0377f3a50843144b1450d3fbe8e4e02a8a
Change-Id: I305539a8598535a73e5cd280b2becdafa740ef97
2019-08-18 12:11:36 +03:00
Roan Kattouw
bcb6b9d0eb MessageCache: Fix isMainCacheable() logic for non-content languages
The way isMainCacheable() was used, it always returned false in
non-content languages, because it would try to find strings like
'hidetoc/fr' in the array of message keys (which contains strings like
'hidetoc').

The consequence of this was that MessageCache would check the database
for a MediaWiki:hidetoc/fr page even if it already knew that that page
didn't exist. This is a substantial performance hit when requesting lots
of messages, like when building version hashes for ResourceLoader's
startup module.

Follows-up 4fc5ba8bf8.

Bug: T228555
Change-Id: I20433175ca919acc1c995f4a9cd50ca53afcdd02
2019-07-20 03:41:14 +00:00
Brad Jorsch
0301c8e03a Default $wgActorTableSchemaMigrationStage to READ_NEW
Probably good to start testing this in CI sometime soon.

The unit tests being changed here are:
* Hacky importing of a revision in MessageCacheTest, changed to use an
  interwiki username.
* WikiPageDbTestBase will get null rather than 0 for ar_user.
* DumpTestCase was using a custom IP $wgUser when creating its test
  revisions, which was winding up referring to an actor_id that had been
  deleted from the database. Fixed by having it use a registered user
  instead.

Also this has MediaWikiTestCase reset the $wgUser User object when the
actor table is truncated, as various tests were otherwise failing because
it was caching a later-deleted actor ID for User:127.0.0.1.

Bug: T188327
Change-Id: Ic483d0fda931810ac639b9de1cc5e5a4ef8161cc
Depends-On: I1bd0288cc132627d75b4001219522ec5e952eda7
2019-04-09 13:50:41 -04:00
daniel
3620931e69 Fix MessagecacheTest::testLoadFromDB_fetchLatestRevision
This re-enables the "flaky" testLoadFromDB_fetchLatestRevision which
was disabled because it failed on random patches for no apparent
reason, as documented in T219042.

The reason was an invalid timestamp in the test data, which caused
the timestamp to default to "now", which was "sometimes" newer than
the timestamp of the revision immediately created before.

Bug: T219042
Bug: T218918
Change-Id: I38f4816b2dc735a7698626c7e3fe4a93ec95a9d1
2019-03-25 11:37:30 +00:00
Max Semenik
6222d8931f Disable flapping MessageCacheTest::testLoadFromDB_fetchLatestRevision()
Bug: T219042
Bug: T218918
Change-Id: I93ed4d088691bfc50aeef1f9c07af5a6dc50de4b
2019-03-23 18:52:13 -07:00
daniel
f8dc579261 Only load latest revision in MessageCache::loadFromDB
In Id044b8dcd7c, we lost a condition that ensured that the cache would
be populated with the latest revision. Now it was being populated with
all revisions, with a random one winning.

Bug: T218918
Change-Id: I1a47356ea35f0abf35bb1a3489d0d3442a3400a5
2019-03-22 15:44:14 +01:00
Aaron Schulz
4fc5ba8bf8 messagecache: check overridable message array in getMsgFromNamespace()
Follow up to a3d6c1411d.

This avoids extra queries for messages that have a software defined value.

Bug: T193271
Change-Id: I25aa0e27200a0b417721cf1fbd34a82095405b89
2018-10-16 20:39:38 +00:00
Brad Jorsch
08e9eb1fef MessageCache: replace should actually replace, not reload
Prior to I462554b30, MessageCache::replace() did just that: it took the
existing cache and updated the one entry.

In I462554b30, the rearrangement of work into a DeferredUpdate
introduced a bug: the in-process cache was updated, but when the shared
cache was loaded later the entry was never updated in there so the
shared caches kept the old value. This was found in code review and
worked around by reloading all the messages from the database instead of
updating the existing cache.

But all that extra work reloading everything from the database causes
major slowness saving any MediaWiki-namespace page when the wiki has
many such small pages. Let's go back and fix the bug so replace() can
again replace instead of reloading everything.

Bug: T203925
Change-Id: Ife8e1bd6f143f480eb8da09b817c85aadf33a923
2018-10-11 11:20:51 -04:00
Fomafix
1472f02b36 Phabricator: Use Tddddd instead of Bug ddddd in comments
Change-Id: Ic9fe03cab270bd6be738af346164ad5d31a0d780
2018-10-04 09:15:02 +02:00
Aaron Schulz
7d2b121ac8 MessageCache: remove confusing and unused $isFullKey parameter from get()
Follows-up cba0fb1c15, which removed the last caller.

Change-Id: I00c17fedff39b1b35519cff2a0f8eac3e4d6f2ab
2018-10-02 23:34:53 +00:00
Aryeh Gregor
90d4f56fe4 Mass conversion of $wgContLang to service
Brought to you by vim macros.

Bug: T200246
Change-Id: I79e919f4553e3bd3eb714073fed7a43051b4fb2a
2018-08-11 22:44:29 -06:00
James D. Forrester
1e9c361960 tests: Replace implicit Bugzilla bug numbers with Phab ones
It's unreasonable to expect newbies to know that "bug 12345" means "Task T14345"
except where it doesn't, so let's just standardise on the real numbers.

Change-Id: I46261416f7603558dceb76ebe695a5cac274e417
2017-02-21 02:14:34 +00:00
Aaron Schulz
c962b48056 Avoid races in MessageCache::replace()
Do the process cache update immediately (as before) but push
the shared cache updates to a deferred update. This update
will thus start with a clear transaction snapshot, so it can
acquire the lock before the first SELECT as is proper.

Also added some missing method visibilities.

Bug: T144952
Change-Id: I462554b300d4688b09ab80cd1bb8a4340ffaa786
2017-01-25 00:46:41 +00:00
daniel
a8995619c1 Avoid rebuilding database fixtures for every test run
This reduces the runtime of database-bound tests by about 40%
(on my system, from 4:55 to 2:47; results from Jenkins are
inconclusive).

The basic idea is to call addCoreDBData() only once, and have
a addDBDataOnce() that is called once per test class, not for
every test method lie addDBData() is. Most tests could be
trivially be changed to implement addDBDataOnce() instead of
addDBData(). The ones for which this did not work immediately
were left out for now. A closer look at the tests that still
implement addDBData() may reveal additional potential for
improvement.

TODO: Once this is merged, try to change addDBData() to
addDBDataOnce() where possible in extensions.

Change-Id: Iec4ed4c8419fb4ad87e6710de808863ede9998b7
2016-03-10 23:44:34 +00:00
Timo Tijhof
ecb47bfb8f phpunit: Abstract user-lang override in MediaWikiTestCase
Removed redundant set up in these classes (same as their paren
class MediaWikiLangTestCase does already).
* BlockTest
* ExportTest
* MWTimestampTest
* TitlePermissionTest

Change-Id: I28d18cb797bb249981727b02dffce4f0d8682b02
2016-03-09 16:55:50 +00:00
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00
Brian Wolff
fb395bba7d Add tests for 47e0f0c3 (MessageCache::normalizeKey())
Change-Id: If8c88383ccfcfcf08d3d85e5648eb338f0d14268
2015-07-19 03:12:33 -06:00
Aaron Schulz
4028bcb506 Fixed race condition in MessageCache::replace
* The cache has to reload and *after* locking to avoid
  losing any concurrent changes.
* Also fixed incorrect assumption in MessageCacheTest.
  Message overrides for the content language do not use
  the language suffix.

Change-Id: I98ff158a1575330bc59efe6badb27f8de8717951
2015-06-04 13:53:37 -07:00
umherirrender
26837cd280 Cleanup some docs (tests)
- Swap "$variable type" to "type $variable"
- Fixed spacing inside docs
- Makes beginning of @param/@var/@throws in capital
- Changed some types to match the more common spelling

Change-Id: Ia041964250d8b7c0349d79dc9b131c5b8696e795
2014-08-11 20:06:52 +02:00
addshore
de7af7ac2c Fix scope on all /phpunit test methods
Change-Id: I3ce92463d485a0fb23e464e9a8059330f32d79af
2013-10-24 10:31:32 +02:00
addshore
339d8cef81 Add @covers for GenderCache + MessageCache tests
Change-Id: I379f2788c1b308354a3dbb73c889aa4a90b2cd20
2013-10-18 13:06:08 +02:00
Tyler Romeo
86b54375de Enable fallback languages when retrieving messages
The core function behind wfMessage() (MessageCache->get()) did not
apply the language fallback chain to on-wiki messages.

This patch has changed the behavior to iterate over all possible
languages, first checking on-wiki and then checking the CDB cache,
until it finds the message. Note that fallback languages never
take precedence over the actual requested language.

This patch was taken from the following changes and then
adjusted to fix issues that caused bug 46579.

* Change-Id: Iaaf6ccebd8c40c9602748c58c3a5c73c29e7aa4d
- Author: Matthew Walker <mwalker@wikimedia.org>
- (cherry picked from commit d434bfcf3b)
* Change-Id: Ib607a446d3499a3c042dce408db5cbaf12fa9e3d
- Author: Mormegil <mormegil@centrum.cz>
- (cherry picked from commit 1b8cb8dc31)

Bug: 1495
Bug: 46579
Change-Id: I420457863eeb79824698d06abc7784032b267af2
2013-05-26 15:46:35 +02:00
Siebrand Mazeland
9d7e9c3141 Revert changes in fallback behavior
This patch set reverts the following:
* Iaaf6ccebd8c40c9602748c58c3a5c73c29e7aa4d
* Ib607a446d3499a3c042dce408db5cbaf12fa9e3d
* Ic59fd20856eb0489d70f3469a56ebce0efb3db13 (partially)

Bug 46579 comment 17 describes a desired solution. In
If88923119179924a5ec091394ccab000ade16b3e we are working on a fix, but it is
taking longer than we anticipated. There was a deployment window planned
about now, but we didn't make it. It makes sense to revert for now, and commit
a proper solution somewhere next week.

Bug: 46579
Bug: 1495
Change-Id: Iac7ac4357dd80e8cdb238a6a207393f0712b3fe5
2013-03-28 10:32:02 +00:00
Siebrand Mazeland
6da93fc6f6 Update code formatting
Also update some previous inconsistencies pointed out by Krinkle in change IDs:
* Ide20743a2e84ff68549286120e6cff9d9f396f54
* I811ca957b6588085d67606ebc0cd4033a1e53839

Change-Id: Ife33b931870d0d7e04fcb40974997436d27f528f
2013-03-27 14:15:11 +01:00
Mormegil
1b8cb8dc31 (bug 1495) Include the site language in the fallback list
In Iaaf6ccebd8c40c9602748c58c3a5c73c29e7aa4d, the behavior of MessageCache
was changed so that it iterates over all possible on-wiki fallbacks including
the site language fallbacks. However, it omitted the site language itself.
Obviously, the problem appears only when the site language is not English,
because English is included always as the fallback language of last resort.
But in other cases, we need to add it explicitly.

Bug: 1495
Change-Id: Ib607a446d3499a3c042dce408db5cbaf12fa9e3d
2013-03-25 23:50:47 +01:00
Timo Tijhof
b36d883017 Tests: Make phpunit providers "public static".
Follows-up I9d2b148e57 (including phpunit/languages this time).

Bug: 46434
Change-Id: I30e5efcd88c516121c454676bd7a18f9b7c8fca6
2013-03-22 03:12:37 +01:00
umherirrender
d9dd04b6f8 fix MessageCacheTest for non-english wikis
MessageCacheTest::addDBData is called before setUp, so wgLanguageCode
and wgContLang are not set to 'en', which result in mediawiki pages
created as $key/en. When the test runs, the language is set correctly
and mediawiki is searching under $key, and does not find anything.

Set wgLanguageCode and wgContLang at the begin of addDBData

1) MessageCacheTest::testMessageFallbacks with data set #0
('FallbackLanguageTest-Full', 'ab', 'ab')
Message fallback failed.
Failed asserting that false matches expected 'ab'.

Change-Id: I8e70b7b424df6a9ad98bfb6c228809f4b4437d1e
2013-03-08 17:09:06 +01:00
Matthew Walker
d434bfcf3b (bug 1495) Enable on-wiki message language fallbacks
The core function behind wfMessage() (MessageCache->get()) did not
apply the language fallback chain to on-wiki messages.

This patch has changed the behavior to iterate over all possible
on-wiki fallbacks (starting with the user's language) before
using the built-in language cache (CDB files). Previously we only looked
for the existence of an on-wiki message in the users's language.

Performance wise, using the 'ab' language ('ru', 'en' fallbacks)
MessageCache::get (Averaged over runs and calls)
New Code: ~8.5% TET (110us/call)
Old Code: ~6.5% TET ( 90us/call)

TET: Total Execution Time

Change-Id: Iaaf6ccebd8c40c9602748c58c3a5c73c29e7aa4d
2013-03-06 19:54:02 +00:00