Commit graph

95 commits

Author SHA1 Message Date
James D. Forrester
8e940c4f21 Standardise all our class alias deprecation comments for ease of grepping
Change-Id: I7f85d931d3b79da23e87b4e5692b2e14be8fcaa0
2024-03-19 20:11:29 +00:00
James D. Forrester
35b2542895 Namespace includes/cache
Bug: T353458
Change-Id: Ic3f3168ef17113f5fb3ec11e0a47f52d65eefba9
2024-02-20 10:28:03 -05:00
James D. Forrester
b16be7a36c Namespace TitleFormatter under \MediaWiki\Title
One of the big ones, so doing this alone.

Bug: T166010
Change-Id: Ic2d59eb6764b1a273ed7162ecabf641f638b8f66
2023-09-19 05:17:18 +00:00
James D. Forrester
a8a6cfd966 Namespace NamespaceInfo under \MediaWiki\Title
One of the big ones, so doing this alone.

Bug: T166010
Change-Id: Ibe103cd362535d3cb94cb8931e95fc74099d1497
2023-09-19 05:17:04 +00:00
James D. Forrester
94ece673b2 Namespace TitleValue under \MediaWiki\Title
One of the big ones, so doing this alone.

Bug: T166010
Change-Id: I4c901d5c32696d8334ec30cede7d9b6f3d8d645e
2023-09-18 18:24:39 +01:00
James D. Forrester
d148989faf LinkCache: Drop addGoodLinkObj(), deprecated in 1.37
Change-Id: I9c426689f0db9658bacc93da1f591e452c51910b
2023-08-23 23:53:51 +00:00
thiemowmde
9b03cde58e Merge sequences of if that end doing the same thing anyway
Motivation:
* Avoid code duplication.
* Hopefully make it easier to read.
* Also order stuff from cheap to expensive, if possible.

Change-Id: I575e3f2027ce60a0d0885be5b9bd3e07bc035eee
2023-06-16 16:09:42 +02:00
Aaron Schulz
1af3c45405 cache: simplify LinkCache good/bad link handling
Combine the good/bad MapCacheLRU instances and use class constants
for row/flag keys of entry arrays. Treat query flags the same way
for missing/existing link entries.

Discourage the use of READ_LATEST via code comments.

Simplify fetchPageRow() given that page_touched is already part
of getSelectFields().

Avoid method call overhead for getGoodLinkFieldObj() type casting.

Create getPersistentCacheKey() method to avoid duplication.

Change-Id: I8701466650fd4988de2fa5aba02d64eac7bd6c1a
2023-03-14 02:20:48 +00:00
Amir Sarabadani
962150af83 cache: Migrate queries to SelectQueryBuilder
In LinkBatch and LinkCache

Bug: T311866
Change-Id: Ic95752af922fd417db700cd9846d5497d48d81f7
2022-12-20 08:59:05 +01:00
Umherirrender
20c3cc6ef1 Remove unused variable from unpacking arrays
Change-Id: Iac27cb4aa936cb494b3e491ce22c88c7fad375a1
2022-11-22 23:21:08 +00:00
Timo Tijhof
1cf6f04768 objectcache: Remove WANObjectCacheReaper feature
Introduced in 2017 with I7f14b9ca2533032 (2e5eb693) but remains
unused at WMF, and disabled by default.

Follows-up I62107789fa (9e49260fc9) which added reap to LinkCache
test cases in 2021.

Change-Id: I0654c29a671467dd6b366f462d1c09b90a273413
2022-10-25 23:09:39 +01:00
Matěj Suchánek
1c48194d4e Remove LinkCache::forUpdate and clean up the constructor
Passing null to the constructor as well as the LinkCache::forUpdate
method have been deprecated since 1.34. Since this is a service
class, it should only be instantiated directly by the service
container anyways.

Change-Id: Id15ccf2af6ef59e7052ea88548464e7481ca73d4
2022-06-16 20:17:54 +02:00
Amir Sarabadani
30aa4679c0 Remove references to legacy page_restrictions field in page table
Bug: T218446
Change-Id: I4d45de0890b96e00d4b24fc96ceffbf336928bc2
2022-05-09 11:20:53 +02:00
Aryeh Gregor
7b791474a5 Use MainConfigNames instead of string literals, #4
Now largely automated:

VARS=$(grep -o "'[A-Za-z0-9_]*'" includes/MainConfigNames.php | \
  tr "\n" '|' | sed "s/|$/\n/;s/'//g")
sed -i -E "s/'($VARS)'/MainConfigNames::\1/g" \
  $(grep -ERIl "'($VARS)'" includes/)

Then git add -p with lots of error-prone manual checking. Then
semi-manually add all the necessary "use" lines:

vim $(grep -L 'use MediaWiki\\MainConfigNames;' \
  $(git diff --cached --name-only --diff-filter=M HEAD^))

I didn't bother fixing lines that were over 100 characters unless they
were over 120 and triggered phpcs.

Bug: T305805
Change-Id: I74e0ab511abecb276717ad4276a124760a268147
2022-04-26 19:03:37 +03:00
Umherirrender
95852cb22b Explicit cast TS_UNIX to int for arithmetic operations and int args
When the called function has a doc of int, it should be cast to be
explicit here.
Also cast for arithmetic operations to be explicit about the number

Change-Id: I905b78dfb66e66443e0e3203488bab5b548db543
2022-01-11 20:13:13 +01:00
TChin
47adb6d65a Refactor global variables to use MediaWikiServices instead
Automatically refactors wg prefixed globals to use MediaWikiServices config using Rector. Doesn't include files that set globals or files that fail CI.

Rector Gist: https://gist.github.com/tchin25/7cc54f6d23aedef010b22e4dfbead228

* This patch uses a modified source code rector library for our specific use case and the rector will have different effects without it.

A writeup for future reference is here: https://meta.wikimedia.org/wiki/User:TChin_(WMF)/Using_Rector_On_MediaWiki

Change-Id: I1a691f01cd82e60bf41207d32501edb4b9835e37
2022-01-10 13:55:53 -05:00
Amir Sarabadani
ec074a6a27 cache: Add four fields to LinkCache::getSelectFields
These are needed PageStoreRecord::REQUIRED_FIELDS and that's why putting
PageStore on top of LinkCache caused a lot of increase in db reads.

Bug: T297669
Change-Id: If77c2f9879d7bae71eb59944efd8b3798d16aa46
2021-12-14 15:10:49 +01:00
Martin Urbanec
b406c52adb LinkCache: Try invalidating cache before throwing
The code that was previously in LinkCache::getGoodLinkRow
may return a cached row object (either from the in-process
cache, or memcached). In some cases, this caused
LinkCache::addGoodLinkObjFromRow to throw, because a field
was missing (although the field is missing only from
the cached copy, not from the database).

To avoid this, try to invalidate the cache
in LinkCache::getGoodLinkRow and retry, before
letting the exception propagate.

Bug: T205349
Change-Id: Ie9e90bf32964047c1831f575cc260d7d62e9e848
2021-11-02 13:10:45 +00:00
vladshapik
1ae8e89eb5 Hard deprecate LinkCache::addGoodLinkObj
LinkCache::addGoodLinkObj was hard deprecated.
Use addGoodLinkObjFromRow() instead. PHPUnit tests
must use LinkCacheTestTrait::addGoodLinkObject().

Bug: T284955
Change-Id: I0c22be2f00e6d6d4ba6dd1511c5385cad55e8ff7
2021-10-26 18:21:32 +03:00
Alexander Vorwerk
0139a3b814 Remove LinkCache::singleton()
Deprecated since 1.28, hard deprecated since 1.37 and unused.

Bug: T249034
Change-Id: I224272e428f49db2498c30e6d12e2280fd580469
2021-09-15 18:05:34 +02:00
daniel
855988fd0e LinkCache: soft deprecate addGoodLinkObj()
addGoodLinkObj() has many optional arguments, but omitting them actually
means corrupting the cache.

Nearly all existing callers are in tests.
So LinkCacheTestTrait::addGoodLinkObject() was created only
for testing. It is better to have this method in the
trait, because building the row directly in each test
would make these tests brittle against schema changes.

The only usage in WMF production code was in WikiPage and has been
fixed.

Bug: T284955
Change-Id: I03a2bd9ed64fcc0281ee29a286c8db395a9e03d9
2021-09-10 16:00:02 +02:00
daniel
3b6345ca16 PageStore: Use LinkCache
This makes the data stored by LinkCache compatible with PageStoreRecord,
so we can use LinkCache inside PageStore.

This causes PageStore to make use of local caching as well as WANObjectCache.

Note that getPageById() does not yet benefit from cache, but does
populate the cache.

Bug: T278940
Change-Id: Icc27a0d9299a3e4ce45521daef87ad06ec06f064
2021-09-01 08:24:34 +00:00
Tim Starling
62bdc0fb60 Suppress LinkCache warning about "non-proper" pages
Every special page link handled by LinkRenderer::makeKnownLink()
would generate a warning in LinkCache about the target being a
"non-proper" page. Duplicate LinkCache's sanity checks to avoid this.

Also improve LinkCache warning messages.

Change-Id: Ia2dc9136cc2edf5ee57e8f1ee54819f891b41a1c
2021-07-27 20:51:42 +10:00
James D. Forrester
719cf161f2 More master -> primary documentation and internal var renaming
Bug: T254646
Change-Id: I63cc8895033714bdfbf09aee933a8f0a43b387f3
2021-07-15 11:20:20 +01:00
daniel
04c2eef862 Improve logging in LinkCache.
When reporting non-preoper LinkTargets or PageReferences, we need to
include the fragment part. Title::__toString does not, so use
TitleFormatter::getFullText instead.

For the purpose of T285951: this patch is not necessary to resolve the
bug, it just improves logging.

Bug: T285951
Change-Id: I1b4fccebae585edf07dccadfb4e8cb48e0b5d597
2021-07-01 19:21:19 +02:00
daniel
9e49260fc9 Make LinkCache behavior more consistent
This patch does several things to LinkCache to make its behavior more
consistent and predictable:

* Methods that set a "good" link now clear the "bad link" flag, and vice
  versa.

* invalidateTitle() now also clears the local cache, not just the
  persistent cache.

* Attempts to set data for LinkTargets that are not proper local pages
  are ignored.

* All methods now accept LinkTarget|PageRecord as the key.
  The ones that previously accepted a string still allow that as well.

* addLinkObject() now consistently uses the local cache if possible,
  and consistently bypasses it if the forUpdate() flag is set.

This is all done in preparation for LinkCache being used inside PageStore.

Bug: T278940
Change-Id: I62107789fa185606a81be20ffa8f0be48297c08f
2021-06-24 18:25:55 +02:00
Alexander Vorwerk
41ae2236f0 Hard deprecate LinkCache::singleton()
deprecated since 1.28 and unused.

Bug: T249034
Change-Id: Ib21d994bf31e14f650a8684628d0b1542085c877
2021-05-03 12:32:11 +00: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
Umherirrender
0f9d316dff Replace wfGetDB with LoadBalancer in LinkCache service
Avoid use of global loadbalancer

Change-Id: I4991e9501cef4fd294d9cae197b31080ca907d45
2020-08-26 19:58:48 +02:00
Reedy
b1e515e36e Fix even more PSR12.Properties.ConstantVisibility.NotFound
Change-Id: I4a30a44bc33fc98479799438d65342f6529e14f9
2020-05-16 00:51:46 +01:00
daniel
495323c063 Remove compat code for pre-MCR schema.
NOTE: This was manually tested to ensure it does not
break updates, see T242764.

Bug: T198557
Change-Id: I1d9f5465018bae10124514bc38169e23e0e613e6
2020-03-24 19:45:47 +01:00
James D. Forrester
4f2d1efdda Coding style: Auto-fix MediaWiki.Classes.UnsortedUseStatements.UnsortedUse
Change-Id: I94a0ae83c65e8ee419bbd1ae1e86ab21ed4d8210
2020-01-10 09:32:25 -08:00
Aaron Schulz
a5c7fd0db2 Move callers away from Title::GAID_FOR_UPDATE
These callers just need to load some data from DB_MASTER.
Subsequent code needing that latest title data should also use the
required flags, rather than relying on flakey global cache state.

Change-Id: I53248ea4b5bf1cd953f956c41b8244831ec5ef04
2019-09-09 13:19:08 -07:00
Aaron Schulz
ebc8342d53 Add NS_MEDIAWIKI to LinkCache::isCacheable() to help MessageBlobStore cache regeneration
Change-Id: I55550a0ea5b9db0c87a67bb8bc06e846db58b9fe
2019-07-10 15:18:48 -07:00
jenkins-bot
c3d8fa1fc3 Merge "Update LinkCache to use NamespaceInfo" 2019-05-06 16:48:20 +00:00
Aryeh Gregor
6f2906e36a Update LinkCache to use NamespaceInfo
Change-Id: Ie9ebc2564861068dea8a64aea5cbeacb03597cea
2019-05-06 09:37:58 +00:00
Aryeh Gregor
0006d922b0 NS_MEDIA also always has page_id 0
Change-Id: I0047e5f8e367fe3e8433e715ea56616a6f8dab85
2019-05-05 11:37:01 +03:00
jenkins-bot
44eecdda93 Merge "Make LinkCache::isCacheable include namespaces like NS_CATEGORY/NS_MODULE" 2019-03-17 18:49:05 +00:00
Aaron Schulz
9804ee9d3a Make LinkCache::isCacheable include namespaces like NS_CATEGORY/NS_MODULE
Category and module pages are some of the most frequently referenced

Change-Id: I6d29e883883cbea596b287494e75663d09130749
2019-03-16 04:48:15 +00:00
Aaron Schulz
93b24207c1 Make EditPage::getTemplates avoid page table query spam
This changes TemplatesOnThisPageFormatter to use LinkBatch
and LinkBatch/LinkCache to manage the field.

Change-Id: I523158cdffc599d4d29bab91c98e55085130cee2
2019-03-15 02:34:00 -07:00
James D. Forrester
33418878f9 Drop LinkCache->addLink(), deprecated in 1.27 and unused
Change-Id: Id6395cc9a122375349b7a13c051049bca3f5ab08
2019-02-09 07:49:09 +00:00
Max Semenik
ca41a48ffe Hard deprecate LinkCache::addLink()
Deprecated in 1.27, no callers.

Change-Id: Ide39566b6741d2b844ddd5c8e62dd0fc0382670a
2018-12-08 22:23:08 -08:00
Kunal Mehta
f503ab10b8 Have LinkCache::getMutableCacheKeys() accept LinkTarget
Change-Id: Id84590b3aa285e31a358877167fe8ff502077f3c
2018-08-14 22:56:27 -07:00
Aaron Schulz
b4c8614885 Convert LinkCache to using MapCacheLRU
Clean up the variable names while at it.

Change-Id: I3b7860c0657111d73567e247bcc1ebcbaef53e22
2018-07-16 21:16:00 +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
9b6168da53 Make LinkCache::invalidateTitle() use the instance WAN cache
Change-Id: Idefcee9b37dcb73b2f18351123b097f4ae68fa76
2018-06-14 21:00:38 -07:00
Aaron Schulz
d735dc562d Move Database and subclasses to Rdbms namespace
Change-Id: I52bef87512f9ddd155d1f4cc0052f6b7a0db5b42
2017-04-12 10:43:57 -07:00
Aaron Schulz
488a647831 Move IDatabase/IMaintainableDatabase to Rdbms namespace
Change-Id: If7e8a8ff574661fd827de8bcec11d2c39a687300
2017-03-28 15:32:38 -07:00
Aaron Schulz
2e5eb693de objectcache: add WANObjectCacheReaper for assuring purges
* This fixes keys based on some sort of change log.
  Updates are wrapped in a mutex and keep track of the
  last known good position.
* Make WANObjectReapUpdate class that cleans up title
  related keys using the recentchanges table. This triggers
  as a deferred updates on RC view.

Change-Id: I7f14b9ca2533032147e62b1a3cc004a23da86579
2017-01-27 02:21:06 +00:00
Aaron Schulz
8ebec93fea Cache NS_TEMPLATE/NS_FILE titles in LinkCache persistently
Queries from parsing are the top use of selectRow() according
to reverse flame graphs on xenon. This does not bother with
pages in namespaces less likely to be included.

Change-Id: Ica5d6e52c830cd71effff21933b8c64691082c11
2016-09-07 00:20:26 -07:00