aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/parser/ParserCacheTest.php
Commit message (Collapse)AuthorAgeFilesLines
* ParserCache: Skip saving of "redirect=no" ParserOutput of redirect pagesdaniel2025-04-011-193/+834
| | | | | | | | | | | | | | | | | | | | | | | Why: - ParserCache refuses to return cache entries for redirect pages. So we shouldn't write these entries into the parser cache in the first place. - If we write but refuse to read, this means there will be a cache write every time a redirect page is retrieved via ParserOutputAccess. What: - Make ParserCache:save() skip entries for redirect pages. This is only reachable via "redirect=no" since by default MediaWiki pageviews render the destination page instead. Note: - It seems we should be able to store redirect pages like any other page in the ParserCache. Why we didn't, and whether we should, is not yet clear. While this is being investigated we should establish consistent behavior for get() and save(). Bug: T389591 Change-Id: I880997193d6de66121c902de80a77c1305bd01d3
* Remove trivial 1-line PHPDocs that just repeat the codethiemowmde2025-01-161-6/+0
| | | | | | | | | | | | | I assume these are all either auto-generated by an IDE or the language-level type declarations have been added later. In any case the comments don't add any new information to what the code already says. This is just extra clutter that makes the code harder to read, I would argue. There are many, many more comments like this. In this patch I intentionally focus on the most trivial 1-line comments. Change-Id: Ia294bf4ce0d8a77036842fe25884bc175c2b0e7d
* Use explicit nullable type on parameter argumentsUmherirrender2024-10-161-4/+4
| | | | | | | | | | | Implicitly marking parameter $... as nullable is deprecated in php8.4, the explicit nullable type must be used instead Created with autofix from Ide15839e98a6229c22584d1c1c88c690982e1d7a Break one long line in SpecialPage.php Bug: T376276 Change-Id: I807257b2ba1ab2744ab74d9572c9c3d3ac2a968e
* Namespace all remaining classes in includes/parserJames D. Forrester2024-10-151-45/+45
| | | | | Bug: T353458 Change-Id: If02cc9b1ff78e26c1cf8c91ee4695845eb133829
* ParserOutput: ensure all created ParserOutputs have a "start of parse" time setC. Scott Ananian2024-10-041-0/+4
| | | | | | | | | | | | | | | | | | | *Most* implementations of ContentHandler::fillParserOutput() ensure that the returned ParserOutput has had ParserOutput::resetParseStartTime() called on it at an appropriate time -- but not *all*. This is a belt-and-suspenders fix that ensures that every code path which creates a ParserOutput has *some* "start time" defined. This could be misleading if the parsing is done first and the parser output is created at the very end of the parse, but in all the code that I've looked at the ParserOutput is the first thing created and so this default should be reasonable. While we're at it, remove the parseStartTime from the serialized form of the ParserOutput, because it is useless after the object is unserialized. Bug: T376433 Change-Id: I3bdf3996401a7d5ac4d8e1e5e6afb7ca410cbe6c
* Remove ParserOutput::getText() calls from core (getRawText)Isabelle Hurbain-Palatin2024-08-191-3/+4
| | | | | | | | | | | | This is the first patch of a series of patches to remove ParserOutput::getText() calls from core. This series of patches should be functionally equivalent to I2b4bcddb234f10fd8592570cb0496adf3271328e. This first patch replaces the calls to getText to calls to ParserOutput::getRawText when the pipeline has no reason to be executed. Bug: T293512 Change-Id: I0ad53cd074ca9cf13e96e6b08179e13aeea180f4
* Add namespace to the root classes of ObjectCacheEbrahim Byagowi2024-07-101-3/+3
| | | | | | | | | And deprecated aliases for the the no namespaced classes. ReplicatedBagOStuff that already is deprecated isn't moved. Bug: T353458 Change-Id: Ie01962517e5b53e59b9721e9996d4f1ea95abb51
* Rename JsonUnserial… to JsonDeserial…James D. Forrester2024-06-121-2/+2
| | | | | | | | This is to make it clearer that they're related to converting serialized content back into JSON, rather than stating that things are not representable in JSON. Change-Id: Ic440ac2d05b5ac238a1c0e4821d3f2d858bc3d76
* Remove all @package commentsthiemowmde2024-05-101-1/+0
| | | | | | | | | | | | I don't think these do anything with the documentation generators we currently use. Especially not in tests. How are tests part of a "package" when the code is not? Note how most of these are simply identical to the namespace. They are most probably auto-generated by some IDEs but don't actually mean anything. Change-Id: I771b5f2041a8e3b077865c79cbebddbe028543d1
* parser: Remove explicit StatsdDataFactory backward-compat logicDerick Alangi2024-03-261-3/+3
| | | | | | | | | | | | | This is a follow-up to: I0b683461212a357c7eb09ddec59c87539e323c65 and I40a8372a76f33c5f62ea73bb1180dd7c47412c89 which explicitly for backward compatibility reasons supports IBufferingStatsdDataFactory. Now that we've fully switched to StatsFactory together with the `copyToStatsdAt()` method, we're fine to fully remove this `instanceof` logic. Bug: T356815 Change-Id: I164d82904b6d3fb575cb973c14f9454569bf09ac
* Merge "[ParserOutput] Rename $mText to $mRawText and ::setText() to ↵jenkins-bot2024-02-211-2/+2
|\ | | | | | | ::setRawText()"
| * [ParserOutput] Rename $mText to $mRawText and ::setText() to ::setRawText()C. Scott Ananian2024-02-201-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ParserOutput::getText() is not a simple getter, but does transformations on the "text" of the ParserOutput; the simple getter is named ::getRawText(). To maintain consistency, rename ParserOutput::setText() to ::setRawText() and the property name ParserOutput::$mText to ::$mRawText so future readers are not confused. The JSON property name as it appears in the serialized ParserCache is left as 'Text' so that we don't have any forward- or backward- rollback issues. Change-Id: I3ef34814ab9473cc70d0a6806e8c5a4a02b73491
* | tests: Fix @covers and @coversDefaultClass to have leading \Reedy2024-02-161-43/+43
|/ | | | Change-Id: I5629f91387f2ac453ee4341bfe4bba310bd52f03
* Rename ParserOutput::{get,set}Timestamp() to ::{get,set}RevisionTimestamp()C. Scott Ananian2024-02-071-1/+1
| | | | | | | | | | This avoids confusion with the "render timestamp" held by the cache, and is consistent with ::get*RevisionId() etc. The old ::getTimestamp() and ::setTimestamp() methods have been deprecated. Change-Id: Idb5e687709c98086c5d3075d31885c58a0723197
* Add ParserOutput::{get,set}RenderId() and set render id in ContentRendererC. Scott Ananian2024-02-071-2/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Set the render ID for each parse stored into cache so that we are able to identify a specific parse when there are dependencies (for example in an edit based on that parse). This is recorded as a property added to the ParserOutput, not the parent CacheTime interface. Even though the render ID is /related/ to the CacheTime interface, CacheTime is also used directly as a parser cache key, and the UUID should not be part of the lookup key. In general we are trying to move the location where these cache properties are set as early as possible, so we check at each location to ensure we don't overwrite a previously-set value. Eventually we can convert most of these checks into assertions that the cache properties have already been set (T350538). The primary location for setting cache properties is the ContentRenderer. Moved setting the revision timestamp into ContentRenderer as well, as it was set along the same code paths. An extra parameter was added to ContentRenderer::getParserOutput() to support this. Added merge code to ParserOutput::mergeInternalMetaDataFrom() which should ensure that cache time, revision, timestamp, and render id are all set properly when multiple slots are combined together in MCR. In order to ensure the render ID is set on all codepaths we needed to plumb the GlobalIdGenerator service into ContentRenderer, ParserCache, ParserCacheFactory, and RevisionOutputCache. Eventually (T350538) it should only be necessary in the ContentRenderer. Bug: T350538 Bug: T349868 Followup-To: Ic9b7cc0fcf365e772b7d080d76a065e3fd585f80 Change-Id: I72c5e6f86b7f081ab5ce7a56f5365d2f75067a78
* Namespace ParserOutputJames D. Forrester2023-12-141-1/+1
| | | | | | | Most used non-namespaced class! Bug: T353458 Change-Id: I4c2cbb0a808b3881a4d6ca489eee5d8c8ebf26cf
* Only cache expensive renderingsdaniel2023-11-301-0/+25
| | | | | | | | | | | | | | | | | | | | Pages that are fast to render can be omitted from the parser cache to preserve disk space and cache write operations. The threshold is configurable per namespace, so the tradeoff can be evaluated based on different access patterns. For example, pages that are accessed rarely, like file description pages on commons, may have a high threshold configured, while pages that are read frequently, like wikipedia articles, may be configured to be always cached, using a 0 threshold. Filtering is based on a time profile recorded in the ParserOutput. A generic mechanism for capturing the timing profile is implemented in the ContentHandler base class. Subclasses may implement a more rigorous capture mechanism. Bug: T346765 Change-Id: I38a6f3ef064f98f3ad6a7c60856b0248a94fe9ac
* Namespace User under \MediaWiki\UserJames D. Forrester2023-09-191-1/+1
| | | | | Bug: T166010 Change-Id: I7257302b485588af31384d4f7fc8e30551f161f1
* Reorg: Move MWTimestamp to MediaWiki\UtilsAmir Sarabadani2023-08-191-1/+1
| | | | | Bug: T321882 Change-Id: I48c10343295c4eb3d9ef8037343b0070e928f040
* Fix more non-database tests accessing the databaseDaimona Eaytoy2023-08-061-8/+19
| | | | | | | | Mock the needed services, or set fixed values to avoid DB lookups, when possible. Add the test to the Database group otherwise, e.g. for things like Skin and Parser that use global state all over the place. Change-Id: I8d87013d89accaf04d0ac19cb4b7216290383eb5
* tests: Make some PHPUnit data providers staticTim Starling2023-03-241-1/+1
| | | | | | | | | | | | | Just methods where adding "static" to the declaration was enough, I didn't do anything with providers that used $this. Initially by search and replace. There were many mistakes which I found mostly by running the PHPStorm inspection which searches for $this usage in a static method. Later I used the PHPStorm "make static" action which avoids the more obvious mistakes. Bug: T332865 Change-Id: I47ed6692945607dfa5c139d42edbd934fa4f3a36
* Reorg: Namespace the Title classJames D. Forrester2023-03-021-1/+1
| | | | | | | | | | | | | | | | | | | This is moderately messy. Process was principally: * xargs rg --files-with-matches '^use Title;' | grep 'php$' | \ xargs -P 1 -n 1 sed -i -z 's/use Title;/use MediaWiki\\Title\\Title;/1' * rg --files-without-match 'MediaWiki\\Title\\Title;' . | grep 'php$' | \ xargs rg --files-with-matches 'Title\b' | \ xargs -P 1 -n 1 sed -i -z 's/\nuse /\nuse MediaWiki\\Title\\Title;\nuse /1' * composer fix Then manual fix-ups for a few files that don't have any use statements. Bug: T166010 Follows-Up: Ia5d8cb759dc3bc9e9bbe217d0fb109e2f8c4101a Change-Id: If8fc9d0d95fc1a114021e282a706fc3e7da3524b
* JsonCodec: fix en/decoding of nested objects and stdClass objectsC. Scott Ananian2023-01-121-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add a type annotation when encoding `stdClass` objects so that we can be sure to decode them as objects instead of arrays. This avoids issues such as that seen in the Graph extension (T312589) where an extension data key is stored as a stdClass. If ParserOutput was computed fresh, a subsequent getExtensionData(..) call will return a stdClass object, but if the ParserOutput was cached, getExtensionData() would return an array. After this change the return type is always consistent. Properly handle nested objects: encode all object values returned by JsonSerializable::jsonSerialize() (so that client is not responsible for implementing this correctly), and decode all object values *before* calling JsonUnserializable::newFromJsonArray (again, so that the client is not responsible for decoding its property values). The new behavior matches how serialize/unserialize is handled in the 'naive' JsonUnserializable{Sub,Super}Class test cases; ParserOutput (the only users of JsonCodec in core) was doing an extra manual decode for the ExtensionData array in ParserOutput::initFromJson that is no longer necessary. The GrowthExperiments and SemanticMediaWiki extensions were working around the non-recursive nature of JsonCodec; this patch depends on patches to GrowthExperiments to make it agnostic about whether object unserialization occurs before or after ::newFromJsonArray() is called, which can then be further cleaned up once this is released. A pull request for SemanticMediaWiki has also been submitted. Bug: T312589 Depends-On: I3413609251f056893d3921df23698aeed40754ed Change-Id: Id7d0695af40b9801b42a9b82f41e46118da288dc
* parser: Mock WikiPage::getContentModel in ParserCacheTest to fix php8.1Brian Wolff2022-07-251-0/+2
| | | | | | | PHP 8.1 doesn't like this returning null. Bug: T313663 Change-Id: I59eb21301aab946b6362fea956b398337af8d971
* Replace deprecated calls `ParserOptions::newCanonical( 'canonical' )`Derick Alangi2022-06-161-35/+35
| | | | | | | | This is a quick find & replace of calls to the deprecated method ParserOptions::newCanonical() when the context is the string literal 'canonical'. This can be safely replaced by called newFromAnon(). Change-Id: If7bb68459b11e0c5f5de188f10fdae85ad1a78bf
* ParserCache: always use JSONdaniel2022-06-071-58/+40
| | | | | | | | | | | | | When JSON support was introduced into ParserCache in 1.36, it was controlled by a feature flag, $wgParserCacheUseJson. The feature flag was "born deprecated" in 1.36. It can now be removed. This means that ParserCache will always store entries as JSON. Support for reading old non-JSON entries remains intact. This is needed when updating wikis from a version older than 1.36 to the current version. Change-Id: Id04e42bfb458d98414bac50e0d6c505e8878e5c0
* Cleanup mixed space/tab line indentUmherirrender2021-09-041-3/+3
| | | | Change-Id: I833052a656b1ce419c0929f6f0514f2a33c2c4cc
* Remove depecated ParserCache::getKey and ::getEtagPetr Pchelko2021-07-271-27/+0
| | | | Change-Id: Idea037eaab851110d0c58f537dafcb2153cd2613
* Tests: remove unneeded tearDown functionsDannyS7122021-07-271-5/+0
| | | | | | | | No need to manually reset MWTimestamp fake time, MediaWikiTestCaseTrait::fakeTimestampTearDown() does that after all tests anyway. Change-Id: Ie45e837c693d7f21b6c7e25471cdaad6f60a3de9
* build: Updating dependencieslibraryupgrader2021-07-221-2/+2
| | | | | | | | | | | | | | composer: * mediawiki/mediawiki-codesniffer: 36.0.0 → 37.0.0 The following sniffs now pass and were enabled: * Generic.ControlStructures.InlineControlStructure * MediaWiki.PHPUnit.AssertCount.NotUsed npm: * svgo: 2.3.0 → 2.3.1 * https://npmjs.com/advisories/1754 (CVE-2021-33587) Change-Id: I2a9bbee2fecbf7259876d335f565ece4b3622426
* ParserCache: only use in-process caching for metadataPetr Pchelko2021-04-061-2/+6
| | | | | | | | | CachedBagOStuff caches negatives, so it breaks PoolCounter. We only need to cache metadata in-process, since it's commonly used twice within the request. Bug: T277829 Change-Id: I11a147c24b6cdb275b521b48802d6f3d0e1a4387
* Convert ParserCache to PageRecordPetr Pchelko2021-04-021-47/+73
| | | | | | | | | | | | | | | ParserOptions not updated cause they depend on Title::getLanguage implementation. Tests converted to not require a DB anymore. Can't be proper unit tests yet due to globals in ParserOptions and fake time hacks, but exec time does go down from 70 seconds to 9 seconds. Page content model is still emitted in the metrics since it was considered useful. Should be removed when we get something like a page type concept. Change-Id: Ib16fd0b5b87ffc3cb4d21f4aa43d1203cb7206d2
* Respect used options for ParserOptions::isSafeToCachePetr Pchelko2021-01-041-2/+20
| | | | | Bug: T269293 Change-Id: Ic3cf908265ad470815f0ac81442d33bde04a5665
* ParserCache: general code cleanup, abstracted expiration checks.Petr Pchelko2020-12-161-3/+3
| | | | Change-Id: I7374f30d582064236b8f782e6a2528eb692e3010
* Make ParserCache use CachedBagOStuffPetr Pchelko2020-12-071-6/+4
| | | | | Bug: T269593 Change-Id: I21e6e39eccad22b781252b142c1e5b079c1ee0b4
* Make ParserCache respect ParserOptions::isSafeToCachePetr Pchelko2020-12-021-41/+78
| | | | | Bug: T269154 Change-Id: I8e9ecd2787aa8d172e708ba64ea936e63fbc6b36
* Introduce JsonCodec to help with serialization/deserializationPetr Pchelko2020-11-191-4/+4
| | | | Change-Id: I5433090ae8e2b3f2a4590cc404baf838025546ce
* Safe ParserOutput extension data and JsonUnserializable helper.Petr Pchelko2020-11-101-2/+7
| | | | | | | | | | | One major difference with what we've had before is that now we actually write class names into the serialization - given that this new mechanism is extencible, we can't establish any kind of mapping of allowed classes. I do not think it's a problem though. Bug: T264394 Change-Id: Ia152f3b76b967aabde2d8a182e3aec7d3002e5ea
* Add some more tests for invalid JSON in ParserCache.Petr Pchelko2020-10-301-4/+28
| | | | Change-Id: I4983592b9a964f4371ef42c824090468eb938862
* ParserCache JSON - do not \u encode unicode and special characters.Petr Pchelko2020-10-221-0/+18
| | | | | | | | | Without passing ALL_OK constant, json-encoding will \u-escape all the unicode, which will blow the size of serialized data, especially on Russian wiki out of proportion. Bug: T263579 Change-Id: Ifaaf1cdfaeeb17c3a99ed742b64ae5cc3157500c
* Normalize error messages for non-serializable propertiesDannyS7122020-10-211-1/+1
| | | | Change-Id: If599082bd4acdc9df5b32aaabf2ba8d24e830914
* Move serializability validation from ParserOutput to ParserCachePetr Pchelko2020-10-151-2/+43
| | | | | Bug: T263579 Change-Id: Iac2dbc817c2e7af4a6d112f01bd380a04354db22
* Use JSON for parser cachedaniel2020-10-131-0/+69
| | | | | | | | | | | This adds JSON serialization and deserialization capabilities to CacheTime and ParserOutput. NOTE: JSON serialization is disabled for now. Merging this patch should not change behavior in production. Bug: T263579 Change-Id: I18187e8bce573d21f6f1bd29106e07c63a6d2f4d
* Hard-deprecate ParserCache::getKey.Petr Pchelko2020-10-131-5/+12
| | | | | | | Bug: T263689 Depends-On: I20b5a3eece79afaac6a4fef733d7a60ea23c6ffe Depends-On: I3ed1188e267f4eaab0ae46f2bc6f9a379dea58ce Change-Id: I30d05ee5b217fce0521d14867309979e76f34760
* Deprecate ParserCache::getKey and replace it with getMetadataPetr Pchelko2020-10-131-0/+104
| | | | | Bug: T263689 Change-Id: I4a71e5a7eb1c25cd53b857c115883cd00160736b
* ParserCache: be resilient to string valuesdaniel2020-10-011-0/+57
| | | | | | | | | | | | | | This makes the parser cache resilient to encountering string values where it is currently expecting to get a ParserOutput objerct from the underlying cache. This provides forward compatibility with a switch to JSON based caching: If we have to switch back after writing JSON to the cache for a while, ParserCache would simply ignore the respective entries, rather than causing fatal errors. Bug: T263579 Change-Id: Iaed582097ab2d05edb4b99a738ac39c530fd63c1
* Cover ParserCache with integration testsPetr Pchelko2020-10-011-0/+388
Bug: T250500 Change-Id: I8c45e7c6706b532f1569d06330cc45e841f208b7