Commit graph

194 commits

Author SHA1 Message Date
Timo Tijhof
67f3df57f9 MessageCache: Replace internal loadedLanguages array with special cache key
Before c962b48056, the 'loadedLanguages' array was used to track
which languages were loaded and in the cache, with 'cache' being a
simple array. In that commit, the 'cache' array also started being used
for incomplete datasets, which didn't affect 'loadedLanguages'.

Then in 97e86d934b, the 'loadedLanguages' array was removed in favour
of checking keys on 'cache' directly, and 'cache' was converted to
MapCacheLRU.

This led to problem where partially loaded data was mistaken for being
full datasets (fatal error, T208897). This was fixed in a5c984cc59,
by bringing back the 'loadedLanguages' array, which fixed the issue from
the POV of partially loaded data.

However, this then exposed a new problem. The 'cache' data can be evicted
by MapCacheLRU, whereas 'loadedLanguages' is not aware of that. Thus it
claims languages are loaded that sometimes aren't. (This only affects web
requests where more than 5 language codes are involved, per MapCacheLRU.)

Fix this by re-removing the 'loadedLanguages' array, this time
strengthening the 'cache' key check to not just check that the root key
exists, but that it is in fact holding the full dataset as generated by
MessageCache::load(). The 'VERSION' key appears to be a good proxy for
that.

Bug: T230690
Change-Id: I1162a3857376aa37e5894ae3c8be84a2295782a3
2019-10-02 22:47:00 +00:00
Daimona Eaytoy
e70b5b3309 Unsuppress other phan issues (part 4)
Bug: T231636
Depends-On: I58e67c2b38389df874438deada4239510d21654f
Change-Id: I6e5fba7bd273219b1206559420b5bdb78734aa84
2019-08-31 17:13:39 +00:00
daniel
b860ef0d13 Avoid fatal errors when reporting exceptions.
When reporting exceptions that occur during initialization, wgUser may
be null. Don't die when that happens.

Change-Id: I65d5a17d80f9021e28a218c7a5a17e399bc7ce98
2019-08-29 13:07:46 +02:00
jenkins-bot
bf7284d975 Merge "MessageCache: Add STRAIGHT_JOIN to avoid planner oddness" 2019-08-28 04:29:31 +00:00
Timo Tijhof
1d7f793108 MessageCache: Increase APC 'messages-big' expiry from 1min to 1h
Bug: T218207
Change-Id: Ic5d2a556912e2a16ee899eec3a0670f00dec9a8c
2019-08-27 22:58:59 +00:00
Timo Tijhof
178d312eb8 MessageCache: Remove $wgMsgCacheExpiry configuration var
This variable has never been set to anything other than the default value of
24 hours as introduced in 2003 (r2203, r2204; or 036ff960ce, edf6b38626).

The variable has never changed in core, it's not overridden at WMF,
and MessageCache is not constructed anywhere other than ServiceWiring.php
anywhere in repos on Wikimedia Gerrit, indexed by MediaWiki Codesearch,
or any GitHub-hosted repository (incl Wikia repos and WikiHow mirrors).

I've also checked all GitHub-hosted repos for boilerplates and/or public
settings files from devs or prod, and couldn't find any example of
this being overridden (after filtering out copies of the core files
themselves). Rather than having to support potentially hard-to-predict
interactions betweeen caching layers by checking its state, make it
a constant so we can code reason about it more easily.

Change-Id: Ie2e139001aae3ac54b509d94a3d917bb408eaca0
2019-08-27 17:33:11 +00:00
Timo Tijhof
f084d0f194 MessageCache: Minor wgMsgCacheExpiry doc fix, and clear constant access
The class used is typed against BagOStuff so access the constant
from there instead.

Bug: T218207
Change-Id: Ie22d6aa5877fb5e8e2ae0b3be87f4b28f45ad763
2019-08-27 16:23:44 +00:00
Brad Jorsch
9e871e05b7 MessageCache: Add STRAIGHT_JOIN to avoid planner oddness
For some unknown reason, when the `actor` table has few enough NS8 rows
compared to `page` MariaDB 10.1.37 decides it makes more sense to fetch
everything from `actor` then join `revision` then `page` rather than
fetching the rows from `page` in the first place.

We can work around it by telling it to not reorder the query, but then
we also have to reorder it ourselves to put `page` first instead of
`revision`.

Bug: T231196
Change-Id: I2b2fb209e648d1e407c5c2d32d3ac9e574e361d5
2019-08-26 15:12:30 -04: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
Timo Tijhof
a5c984cc59 MessageCache: Restore 'loadedLanguages' tracking for load()
This was removed in 97e86d934b in 2018 in favour of using
`$this->cache->has($code)`. This is a problem because there
are cases where only a narrow subset of that structure is
populated (by MessageCache->replace) without things like
$this->overridable (or anything else that MessageCache->load does)
having ocurred yet.

The assumption that keys are only added to $this->cache by
MessageCache->load (or after that method has been called) was
actually true at some point. But, this changed in 2017 when
commit c962b48056 optimised MessageCache->replace to not call
MessageCache->load.

Bug: T208897
Change-Id: Ie8bb4a4793675e5f1454e65c427f3100035c8b4d
2019-07-29 19:22:10 +01: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
Simon Legner
e96c15a521 Fix typos in MessageCache
Change-Id: I5ede5ad5687144535545248940ca6f676f514900
2019-05-28 21:16:05 +02:00
Roan Kattouw
a6643499a4 Obtain MessageBlobStore instance in a consistent way
Use MediaWikiServices (not OutputPage) to obtain a ResourceLoader
instance, then call ->getMessageBlobStore() to obtain its
MessageBlobStore instance (don't construct a new one).

Change-Id: I6b8bacac9888b5807328eece01134a6c5747dc72
2019-05-07 01:09:45 +00:00
Aryeh Gregor
e6df285854 Remove all $wgParser use from core
Bug: T160811

Change-Id: I0556c04d33386d0339e02e2bf7a1ee74d97c2abd
2019-04-17 15:16:50 +03: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
Bill Pirkle
f7afe42713 Remove many references to db fields being retired as part of MCR Schema Migration
Remove many references to database fields rev_text_id and ar_text_id,
which are being retired as part of MCR Schema Migration.
Some references remain, and will be removed under other patchsets
or other tasks.

Bug: T198341
Change-Id: Id044b8dcd7c9d09d5d6037eb732f6a105933f516
2019-03-19 10:50:54 -05:00
Gilles Dubuc
de3fc8f765 Log error when array_flip fails in MessageCache load
Bug: T208897
Change-Id: If6e7a6a3019abbdc11b6604ec706cc88bfddf128
2018-11-19 11:49:23 +01:00
Aaron Schulz
387071ecc2 Avoid broken markup due to conversion table DB queries in Installer:parse()
Bug: T207979
Change-Id: I6a196a64865533a073fadc4a07f5627b67924921
2018-10-27 16:41:33 -07:00
C. Scott Ananian
4b1db1190b Tidy Message::parseAsBlock() by enabling tidy in MessageCache
We are incrementally removing places where the parser is used with
tidy disabled, since future parsers will not support such operation.

Bug: T198214
Change-Id: I0f417f75a49dfea873e9a2f44d81796a48b9f428
2018-10-17 02:43:07 +00: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
jenkins-bot
d69b967481 Merge "MessageCache: replace should actually replace, not reload" 2018-10-11 20:56:33 +00:00
jenkins-bot
7c091e68e9 Merge "messagecache: avoid caching message pages that do not override" 2018-10-11 18:59:24 +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
Aaron Schulz
a3d6c1411d messagecache: avoid caching message pages that do not override
Clean up individual message cache handling when the master key is
volatile. The goal is not to treat the message as gone but to re-fetch
it when accessed rather than cache the value in the main/process cache.

Bug: T193271
Change-Id: I4bcaf10c1516e7c96c2d0963722affeaf80272e0
2018-10-10 12:35:07 -07:00
Aaron Schulz
59242afaa7 messagecache: use MergeableUpdate for the deferred replace() update
This combines the load loop for multiple messages for a language code.

Bug: T203925
Bug: T193271
Change-Id: Ie5e1e83d6740344b7ca641c99fb3bd4ad5718492
2018-10-05 20:14:41 +00:00
Aaron Schulz
548c92a332 MessageCache: do not store the EXCESSIVE array as it is only needed for HASH
This saves space as the number of entries becomes larger.

Bug: T193271
Change-Id: I32d7512d7f05ae7c9a69b88cd19df64d7a21b4a1
2018-10-04 02:22:05 +00: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
Umherirrender
173df1768b Fix logged method in MessageCache::replace/loadCachedMessagePageEntry
Seeing {closure} in the logs as caller is not helpful

Change-Id: Iddfb6042bba2a59a9f21f533b748c96478a87b97
2018-09-30 17:37:51 +00:00
Umherirrender
40d3ce8d17 Reduce calls to MediaWikiServices::getInstance()
In some functions MediaWikiServices::getInstance() was called twices or
in loops. Extract the variable to reduce calls.

Change-Id: I2705db11d7a9ea73efb9b5a5c40747ab0b3ea36f
2018-08-18 06:02:39 +02:00
jenkins-bot
a8b828a774 Merge "Avoid MapCacheLRU error when MessageCache fails to load" 2018-08-14 16:32:07 +00:00
Fomafix
0a0d5cb7f7 Fix typos
Bug: T201491
Change-Id: I25a27d11faabe2f5fa02950c7a4fb58b13fb3662
2018-08-14 09:52:19 +00:00
Aaron Schulz
65ad02955c Avoid MapCacheLRU error when MessageCache fails to load
Bug: T201893
Change-Id: I6093113a3ffa8092dea3351a6ed6c815c7ff7162
2018-08-13 23:03:27 -07: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
Aaron Schulz
70b38d4d2b Make MessageCache use APC for big messages
Bug: T118893
Change-Id: I418d0ca490911d7ee4213fe1728cfbc637ef8b10
2018-07-25 13:24:52 -07:00
Timo Tijhof
c9bcbaa558 cache: Minor docs for MessageCache interaction with WANObjectCache
Follows-up 04bc03a29a.

Change-Id: I8fb810fc2e08277bb64fa18595483a2161cfb1cc
2018-07-25 13:28:19 +00:00
Aaron Schulz
04bc03a29a Make MessageCache use getWithSetCallback() for big messages
Change-Id: I8f93e1dffbcbbabf4d7cb361b001d8ca6e7ad954
2018-07-19 12:41:14 +00:00
Umherirrender
130ec2523d Fix PhanTypeMismatchDeclaredParam
Auto fix MediaWiki.Commenting.FunctionComment.DefaultNullTypeParam sniff

Change-Id: I865323fd0295aabd06f3e3c75e0e5043fb31069e
2018-07-07 00:34:30 +00:00
Aaron Schulz
97e86d934b Limit the number of cached languages in MessageCache via MapCacheLRU
Change-Id: I37a128cfc553e0edaab524098461776cec3fe08a
2018-07-03 11:03:14 +00:00
Aaron Schulz
5c0937b167 Make MessageCache::getMsgFromNamespace() process cache hook-defined keys
Change-Id: I6f8a0c002b54dc48bc3e6902ab1ba41b2f99412a
2018-06-23 17:59:12 +01:00
Bartosz Dziewoński
0313128b10 Use PHP 7 "\u{NNNN}" Unicode codepoint escapes in string literals
In cases where we're operating on text data (and not binary data),
use e.g. "\u{00A0}" to refer directly to the Unicode character
'NO-BREAK SPACE' instead of "\xc2\xa0" to specify the bytes C2h A0h
(which correspond to the UTF-8 encoding of that character). This
makes it easier to look up those mysterious sequences, as not all
are as recognizable as the no-break space.

This is not enforced by PHP, but I think we should write those in
uppercase and zero-padded to at least four characters, like the
Unicode standard does.

Note that not all "\xNN" escapes can be automatically replaced:
* We can't use Unicode escapes for binary data that is not UTF-8
  (e.g. in code converting from legacy encodings or testing the
  handling of invalid UTF-8 byte sequences).
* '\xNN' escapes in regular expressions in single-quoted strings
  are actually handled by PCRE and have to be dealt with carefully
  (those regexps should probably be changed to use the /u modifier).
* "\xNN" referring to ASCII characters ("\x7F" and lower) should
  probably be left as-is.

The replacements in this commit were done semi-manually by piping
the existing "\xNN" escapes through the following terrible Ruby
script I devised:

  chars = eval('"' + ARGV[0] + '"').force_encoding('utf-8')
  puts chars.split('').map{|char|
    '\\u{' + char.ord.to_s(16).upcase.rjust(4, '0') + '}'
  }.join('')

Change-Id: Idc3dee3a7fb5ebfaef395754d8859b18f1f8769a
2018-06-04 16:20:13 +00:00
Bartosz Dziewoński
485f66f174 Use PHP 7 '??' operator instead of '?:' with 'isset()' where convenient
Find: /isset\(\s*([^()]+?)\s*\)\s*\?\s*\1\s*:\s*/
Replace with: '\1 ?? '

(Everywhere except includes/PHPVersionCheck.php)
(Then, manually fix some line length and indentation issues)

Then manually reviewed the replacements for cases where confusing
operator precedence would result in incorrect results
(fixing those in I478db046a1cc162c6767003ce45c9b56270f3372).

Change-Id: I33b421c8cb11cdd4ce896488c9ff5313f03a38cf
2018-05-30 18:06:13 -07:00
jenkins-bot
c122357c72 Merge "Switch the sidebar cache to using checkKeys" 2018-02-20 22:09:50 +00:00
Aaron Schulz
cf54d68968 Switch the sidebar cache to using checkKeys
The avoids the long delete() loop in MessageCache::replace()
and has better separation of concern.

Change-Id: I0acb0119058fa92fcafb52a5850f5dad4aaa94d2
2018-02-19 04:10:39 -08:00
Aaron Schulz
394b272a64 Cleanup IDEA warnings in MessageCache
Change-Id: I0ced7c7289918f78bb6f3682ae974fe0c04a1e04
2018-02-19 12:08:15 +00:00
Brad Jorsch
2791fb0861 Hard-deprecate ParserOutput stateful transform methods
This also removes all the in-core calls that had been kept for the
benefit of extensions, and causes them to not have any effect since
anything that had been calling them was already either a no-op or will
probably be broken now that nothing in core is setting or checking the
flags.

Change-Id: Id22c1a5a6d6a249debb14063ae3f8838d105b634
2018-02-13 12:28:36 -05:00
Brad Jorsch
d511626236
Add 'unwrap' ParserOutput post-cache transform
And deprecate passing false for ParserOptions::setWrapOutputClass().

There are three cases for the Parser wrapper: the default
mw-parser-output, a custom wrapper, or no wrapper. As things currently
stand, we have to fragment the parser cache on each of these options,
which uses a nontrival amount of storage space (T167784).

Ideally we'd do all the wrapping as a post-cache transform, but
TemplateStyles needs to know the wrapper in use in order to properly
prefix its CSS rules (that's why we added the wrapper in the first
place). So, second best option is to make *un*wrapping be a post-cache
transform and make "custom wrapper" be uncacheable.

This patch does the first bit (unwrapping as a post-cache transform),
and a followup will do the second part once the deprecation process is
satisfied.

Bug: T181846
Change-Id: Iba16e78c41be992467101e7d83e9c3134765b101
2018-02-01 14:24:27 -08:00
Umherirrender
3124a990a2 Use ::class to resolve class names in includes files
This helps to find renamed or misspelled classes earlier.
Phan will check the class names

Change-Id: I07a925c2a9404b0865e8a8703864ded9d14aa769
2018-01-27 20:34:29 +01:00
Thiemo Mättig
ef470ebf7f Remove @param comments that literally repeat what the code says
These comments do not add anything. I argue they are worse than having
no comments, because I have to read them first to understand they
actually don't explain anything. Removing them makes room for actual
improvements in the future (if needed).

Change-Id: Iee70aad681b3385e9af282d5581c10addbb91ac4
2018-01-10 14:14:26 +01:00
daniel
6af796f3e0 MCR: Deprecate and gut Revision class
This is a re-submission of I4f24e7fbb68.

As a first major step towards Multi-Content-Revisions (MCR),
this patch turns the Revision class into a legacy proxy for
the new RevisionRecord and RevisionStore classes.

Backwards compatibility is maintained for all but some
rare edge cases, like constructing a completely empty
Revision object.

For more information on MCR, see
<https://www.mediawiki.org/wiki/Requests_for_comment/Multi-Content_Revisions>.

NOTE: once this is merged, verify create/delete/restore cycle on beta,
      ideally with emulated replication lag.

Bug: T174025
Change-Id: Ia4c20a91e98df0b9b14b138eb4825c55e5200384
2017-12-21 18:08:54 +00:00
Daniel Kinzler
09bf4f5bb2 Revert "[MCR] Turn Revision into a proxy to new code."
This reverts commit 9dcc56b3c9.

With this patch applied, newly created revisions are sometimes not found
just after submitting an edit, until replicas have caught up.

Our best theory is that it somehow interfere with ChronologyProtector,
but we don't have a good idea how.

Also, as legoktm mentioned, the commit message is terrible and needs fixing.

Change-Id: Idf3404f3fa8f8d08a7fb2ab8268726e2c1edecfe
2017-12-19 12:38:48 +00:00