Commit graph

155 commits

Author SHA1 Message Date
drynok
9b202c52f4 Change WatchedItemStore to cache an array instead of MapCacheLRU
Updated the closure in WatchedItemStore::resetNotificationTimestamp() to return
an array obtained from MapCacheLRU->toArray(), instead of an object.
Updated the two places that fetch from the cache to read cache entries in either format,
for backwards compatibility.

Added testResetNotificationTimestamp_stashItemTypeCheck test to
WatchedItemStoreUnitTest which verifies correct behaviour with
cache values supplied by the test case.

Bug: T282105
Change-Id: Ibfe4c205ffdf7af7087f6f862004b95b29bdc394
2021-10-18 13:00:03 -07:00
Tim Starling
a0725871c7 WatchedItemStore: forwards compatibility for stash value change
Stash values will change from a MapCacheLRU to an array, to avoid a
warning. Implement the read side of the change so that the write side
can be safely reverted.

Bug: T282105
Change-Id: I8d60ae709004a8aba9ad916e1a5fd05406a05984
2021-10-05 11:35:00 +11:00
Amir Sarabadani
e7c77f4409 watcheditem: Use lazy push for WatchlistExpiryJob
WatchlistExpiryJob is being queued in some edits and they are being pushed directly.
This means in some edits, the appserver opens a request, communicate to
eventgate and then closes it, adding around 40ms to the time to save the edit.

You can see it in flamegraph of EditAction:
https://performance.wikimedia.org/arclamp/svgs/daily/2021-09-30.excimer-wall.all.fn-EditAction.svgz

It's not an urgent job and can be pushed later through deferred update
instead. The important thing is that it gets batched through all other
jobs being pushed.

Originally added in Ica8ab92837c38.

Bug: T292048
Bug: T255502
Change-Id: I2b0612052d6b34545f50d9cd9a28da50f14a16b4
2021-10-01 14:33:00 +00:00
DannyS712
db49026745 ActivityUpdateJob: accept PageReference
For both LinkTarget and PageReference, just extract
namespace and dbkey and pass those in the array
of parameters to Job::__construct().

Allows a bunch of simplification to WatchedItemStore.

Bug: T291531
Change-Id: Id150d0c62af38d4b3d17e5698866127c6e04717e
2021-09-21 23:30:51 +00:00
DannyS712
20aa78f213 Drop deprecated BeforeResetNotificationTimestamp hook
Deprecated in 1.37 and unused

Allows a bunch of cleanup for WatchedItemStore.

Bug: T271715
Change-Id: I328cf49c3e85da2069b620f8c63670d93608a784
2021-09-21 23:09:18 +00:00
jenkins-bot
2202cebdeb Merge "Using @return never documentation on always-throw-function" 2021-09-08 03:12:06 +00:00
jenkins-bot
198bb440be Merge "Simplify WatchedItemQueryService::getRecentChangeFieldsFromRow" 2021-09-07 16:23:18 +00:00
Umherirrender
44fd53fee3 Using @return never documentation on always-throw-function
This helps phan to detect unreachable code and also impossible types
after the functions.
It helps phan to avoid false positives for array keys
when the keys are checked before

Bug: T240141
Change-Id: I895f70e82b3053a46cd44135b15437e6f82a07b2
2021-09-07 17:29:03 +02:00
Umherirrender
4d42b5e86e docs: Change wording master to primary in comments and log text
Bug: T254646
Change-Id: I5379dc79be60c99f0a30f74e5d624f81fe6f921b
2021-09-01 23:04:40 +02:00
Daimona Eaytoy
9cca05a8e8 Add typehints to several methods
These not only make the code more robust, but also help a lot when
writing unit tests: if a method is return-typehinted and its class is
mocked, the mock method will automatically return a mock of its declared
return type. Otherwise it will return null, and developers are forced to
manually mock the method if the return value is used by the SUT in a way
that doesn't accept null.

Depends-On: I628fcb1807133390c7b9b47984f512f5b1ae58d0
Depends-On: I7080bc505f5838b2f51a368da562104e206063b0
Change-Id: I59068cfed10aabf6c6002f9e9312a6ef6e7e9441
2021-08-31 16:19:13 +00:00
jenkins-bot
0eb7f5d893 Merge "WatchedItemStore: clean up, simplify, and misc tweaks" 2021-07-26 14:18:42 +00:00
DannyS712
92fcb0e5c9 Remove WatchedItemStoreInterface::enqueueWatchlistExpiryJob
Deprecated since 1.36 and unused

Change-Id: Ie72e6ef43b258e07fd0f6ec09d7250a6e320f1ca
2021-07-23 08:52:26 +00:00
DannyS712
b7b84e2112 WatchedItemStore: clean up, simplify, and misc tweaks
- Add some documentation
- Add a bunch of typehints
- Add helper method ::modifyForExpiry to reduce duplication
around queries that need to be modified if watchlist expiration
is enabled, inspired by ChangeTags::modifyDisplayQuery
- Add some whitespace for readability
- Remove documentation stating that some parameters to
private methods were deprecated being a LinkTarget rather
than a PageIdentity - the deprecation is in the public
interface of the class, and in the methods that call
these private helper methods, we don't deprecate the internal
calls

Should be a no-op

Change-Id: I80088ca8238898741f04c1e9ea854168f252e174
2021-07-23 08:15:23 +00:00
libraryupgrader
5357695270 build: Updating dependencies
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
2021-07-22 03:36:05 +00:00
DannyS712
e16e6c4ab8 WatchedItemStore: use UserFactory::newFromUserIdentity()
Currently, we have a UserIdentity, we retrieve the user id,
and then we create a User object based on the id. Instead,
create the User object based on the UserIdentity directly,
so that if the UserIdentity happens to already be a full User
object no change is needed.

This allows us to simplify WatchedItemStoreUnitTest by
not needing to tailor the mock UserFactory to the specific
user ids that we are using in each test case.

Change-Id: I52918b4f4c7d44086ea4fcdabdbfe14197c06373
2021-07-20 12:10:20 +00:00
DannyS712
ae4efe66c6 Don't pass unneeded variables into anonymous functions
Change-Id: Iad4d1dc4727828f9e0120c8bf99dc245a29ee14d
2021-07-13 19:48:26 +00:00
Petr Pchelko
7fbe4ced2d Remove WatchedItem::getUser, deprecated and unused
Bug: T274972
Change-Id: I045d0d1a402a1045389d039a9276de0a46809388
2021-06-17 14:04:00 -07:00
Matěj Suchánek
b53018f4a7 Simplify WatchedItemQueryService::getRecentChangeFieldsFromRow
Use array_filter with ARRAY_FILTER_USE_KEY instead of retrieving
and filtering keys separately and make the code cleaner. This
resolves a fixme remark in the code.

Change-Id: I6e9f08522cbef1318be541982ca8c2a359fbe046
2021-06-15 10:26:42 +00:00
Tim Starling
9c3c0b704b Use array_fill_keys() instead of array_flip() if that reflects the developer's intention
array_fill_keys() was introduced in PHP 5.2.0 and works like
array_flip() except that it does only one thing (copying keys) instead
of two things (copying keys and values). That makes it faster and more
obvious.

When array_flip() calls were paired, I left them as is, because that
pattern is too cute. I couldn't kill something so cute.

Sometimes it was hard to figure out whether the values in array_flip()
result were used. That's the point of this change. If you use
array_fill_keys(), the intention is obvious.

Change-Id: If8d340a8bc816a15afec37e64f00106ae45e10ed
2021-06-15 00:11:10 +00:00
DannyS712
aa417bff5f Hard deprecate BeforeResetNotificationTimestamp hook
Appears unused

Bug: T271715
Change-Id: I02f9ee6cd9e4abd8d045fd2e1ae767869bee4a1a
2021-06-06 14:01:18 +00:00
DannyS712
948abe3cf0 Migrate WatchedItemQueryService to Authority
Instead of using a PermissionManager

Required some changes to the creation of
the mock users in WatchedItemQueryServiceUnitTest,
simplified those changes by combining the various
helper methods that returned user mocks.

Change-Id: Id8382a5884133013e3da0d3318a41f8c451c3039
2021-05-26 17:38:16 +00:00
James D. Forrester
f2f9345e39 Replace uses of DB_MASTER with DB_PRIMARY in documentation and local variables
This is just a start.

Bug: T254646
Change-Id: I9213aad4660e27afe7ff9e5d2e730cbf03911068
2021-05-14 12:40:34 -07:00
James D. Forrester
64898405cb build: Upgrade mediawiki-codesniffer from v35.0.0 to v36.0.0
Change-Id: I8905d0d69738a1cd6997c104080fdf128d315e8b
2021-04-29 13:00:15 -07: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
Tim Starling
fd01c53778 Stop using legacy ActorMigration field "rc_user"
Bug: T278917
Change-Id: I4d6c175c637a2cb26c63e0b2b27d5ea8ce6b1e0d
2021-04-28 16:29:04 +10:00
DannyS712
1acd9531d3 Fix NoWriteWatchedItemStore::countWatchersMultiple
Should call the same ::countWatchersMutiple on the
actual store, not ::countVisitingWatchersMultiple

Has been broken since NoWriteWatchedItemStore was
first introduced, see 1ff58fc746

Change-Id: I20ab9a130f5bfe8b888ad08ea5852f13a03184f8
2021-04-23 15:27:56 +00:00
jenkins-bot
8b37995ed2 Merge "Convert WatchedItem et al to PageIdentity" 2021-03-26 20:16:54 +00:00
Cindy Cicalese
a78184782f Convert WatchedItem et al to PageIdentity
Change-Id: Iddcd109b7f78efdbcb0e4016e81fd2c8d4666b46
2021-03-26 15:51:19 -04:00
DannyS712
8b7c992235 Add WatchedItemStore::maybeEnqueueWatchlistExpiryJob
Replaces ::enqueueWatchlistExpiryJob which is hard deprecated
New method checks if watchlist expiration is enabled, and if
so enqueues the job based on the $wgWatchlistPurgeRate,
instead of forcing calls to handle that logic

Change-Id: I07a96941efd1a240846284d5c86db66c6ba45156
2021-03-25 15:57:03 -04:00
DannyS712
62de663845 Convert WatchedItemStoreUnitTest to pure unit tests
Required some fixes:
* getMockJobQueueGroup - add a parameter to not mock the
behavior of calling 'lazyPush'. By default, the mock
has a callback to just run the job being pushed, but
some tests don't want to run the job
* WatchedItemStore::updateNotificationTimestamp - use
$this->deferredUpdatesAddCallableUpdateCallback to allow
testing the updates

Change-Id: I4d35266340e1c44fe2154198de416ad93bfedf1d
2021-03-21 20:30:01 +00:00
DannyS712
f5ca149fef WatchedItemStore: inject a TitleFactory
Hopefully we can make WatchedItemStoreUnitTest
actually be a unit test as a follow-up

Change-Id: I8b6418a0661fe5734c02bda95b34dd469fd9c2b0
2021-03-17 14:12:24 +00:00
Vadim Kovalenko
65af17e7c8 Hard deprecate WatchedItem::getUser in favor of ::getUserIdentity
Bug: T274972
Change-Id: I8815ea33cd534f497d7a935946e6ad250f828a7c
2021-02-26 03:29:45 -05:00
Umherirrender
8de3b7d324 Use static closures where safe to use
This is micro-optimization of closure code to avoid binding the closure
to $this where it is not needed.

Created by I25a17fb22b6b669e817317a0f45051ae9c608208

Change-Id: I0ffc6200f6c6693d78a3151cb8cea7dce7c21653
2021-02-11 00:13:52 +00:00
Cindy Cicalese
5576727771 Make UserIdentity objects aware of which wiki they belong to.
Bug: T260933
Change-Id: Ic986640cc34e6ec6be239e410a8334f0e299c682
2021-02-02 16:10:51 +00:00
MusikAnimal
56ccf11a6c WatchedItemStore: Use REPLACE when inserting expiries after page move
Sometimes when moving pages, a row for the target page may already exist
in the watchlist_expiry table. The exact scenario that's causing the
prod errors could not be repo'd in tests or locally, but using REPLACE
should be a safe solution.

Tests updated to actually verify the expiry of the new title, if
present, is overriden with the old one following the page move.

Bug: T271971
Change-Id: Id4d46fcdea4816e5714d266985ba86fdc6450cfb
2021-01-14 14:22:06 -05:00
DannyS712
b40ca337c9 WatchedItemStore: use UserFactory
Will allow for converting to true Unit tests

Change-Id: I0ef2ada0d5ee9a80a104cb9b07a50e3887d02dd3
2021-01-10 03:12:25 +00:00
MusikAnimal
21d6f1cd6a ApiQueryInfo: Return watchlist expiry when applicable for inprop=watched
The expiry is returned as a separate key, 'watchlistexpiry', to match
other APIs, and because some clients might expect 'watched' to be a
boolean (or blank string depending on the formatversion).

Bug: T268834
Change-Id: I227d6ed42e70ba1ddec0139e8198f536dfba0b46
2021-01-06 13:51:27 -05:00
DannyS712
ef6d79a6bb WatchedItemQueryService: Add expiry to items
So that ApiQueryWatchlist can include it

Bug: T263796
Follow-up: 9fefe2eac0
Change-Id: I18bfc19e992a00549cdcd14db436cd65f8654cb6
2020-12-01 01:30:46 +00:00
jenkins-bot
c360fd7f19 Merge "Use LinkBatchFactory in WatchedItemStore" 2020-11-06 21:24:23 +00:00
Umherirrender
17ec6f6a19 Use LinkBatchFactory in WatchedItemStore
Change-Id: I870b6b9780f0131fb8caa6d48999f3ab8800dd81
2020-11-02 19:01:25 +01:00
DannyS712
a00cddef96 Inject UserFactory into WatchedItemQueryService
Bug: T265311
Change-Id: I2bf6782b4f83f7ce0f0809dcb09d83c82fc13b6c
2020-10-12 21:36:21 +00:00
hmonroy
45bb027122 Normalize WatchedItem expiry field
Normalize watchlist expiry field so that it is set to
ConvertibleTimestamp and the expiry value validation is
handled by the WatchedItem class.

Bug: T260868
Bug: T260009
Change-Id: I3ef31900cfbe7bce23c5ebe1db777a5137ea6167
2020-10-06 13:00:50 -07:00
daniel
2e57447c58 Document hook names in hook interfaces.
Bug: T258665
Change-Id: Ifddbf57f8aa2e3eb0d5845601376cbafa08ed407
2020-09-27 12:03:12 +02:00
Sam Wilson
99b3027e27 Correct success messages for action=watch
Fix up display of success messages after action=watch is
submitted. This adds two new messages for when the remaining
watch period is less than a day, and fixes the display of
the other six messages. The factors for which message is used
are:

* watchlist expiry feature flag;
* article vs talk page;
* temporarily vs permanently watched; and
* hours or whole days remainig in watch period.

Bug: T259055
Change-Id: Ice3a30028d0bec5c5f4e4b9ce9e95b6553bdabdf
2020-09-03 05:47:08 +08:00
jenkins-bot
d668b509e8 Merge "WatchedItemStore: Cache single WatchedItems with preexisting expiry" 2020-08-21 08:00:44 +00:00
MusikAnimal
c75f250cf6 WatchedItemStore: Cache single WatchedItems with preexisting expiry
This commit makes three changes:

1) Re-fetches the expiry before caching WatchedItems in addWatch().
   Sometimes (as with action=rollback) addWatch() is called without an
   expiry, even though one currently exists. So we must query for the
   preexisting expiry to ensure it persists in the process cache,
   otherwise the star in Vector will be full when it should be a
   half-star.
2) Removes caching of WatchedItems within addWatchBatchForUser(). We do
   not want to fix #1 above within addWatchBatchForUser() as this would
   mean we'd need to fetch expiries en masse, when seemingly only a
   single WatchedItem needs the process cache (the page you're viewing).
   Bulk caching was added in Ie4b69c985815a77b70692db0c4dbf52e1a6a018d
   solely for the benefit of a single page (T28292), so it seems safe to
   move the caching to addWatch().
3) Changes User::addWatch() to use WatchedItemStore::addWatch() instead
   of addWatchBatchForUser(). This is to ensure the WatchedItem is
   stored in the process cache for the aforementioned reasons.
   Accordingly the docblock for addWatchBatchForUser() now encourages
   use of addWatch() for a single page/talk page.

Bug: T259379
Change-Id: I3a071f4fbc28fcc96ca7768e31c6810ff7b8e605
2020-08-21 06:29:20 +00:00
Aryeh Gregor
a24e8a06b5 Mark CONSTRUCTOR_OPTIONS as internal
These were never meant to be part of the public interface and should not
ever have been marked with @since. They're only useful for constructing
the respective objects, which no outside users should be doing.

Change-Id: I86e01272d46fc72af32172d8a12b9180971d4613
2020-08-21 00:18:45 -04:00
hmonroy
0c2cc49bdc Update language in watchlist expiry
Update watchlist expiry language indicators (dropdowns, tooltips, watch
via star, watch via edit):
 * Change "Permanently" to "Permanent"
 * Change "XX days left" and "Expires in X days" to "XX days left in
   watchlist"
 * Update the "Click.." sentence by star to "Click to remove it."
 * Change watch period for a page that is less than "1 day left" to "A
   few hours left"

Bug: T253135
Bug: T255632
Change-Id: I114c6f77e86ad81b1810fedcd49f52c88700ca16
2020-08-14 11:47:03 -07:00
jenkins-bot
54fcd1c72f Merge "Default to using watchlist expiry of old page when moving pages" 2020-08-06 04:32:24 +00:00
MusikAnimal
884fa47d09 Default to using watchlist expiry of old page when moving pages
Expiries are copied post-send so as to not slow anything down.

Note the expiry feature has been disabled in some unit tests that mock
database queries, simply because these tests are so hard to maintain and
are very fragile. The logic introduced with this patch is covered by the
integration tests.

Bug: T257259
Change-Id: I4223eaa6782a319fb684acf656f54b88a92e5288
2020-08-05 23:32:00 -04:00