Page MenuHomePhabricator

Maintenance script for changing user settings
Closed, ResolvedPublic

Description

We need to move users who are in the control group and have registered before the start of the experiment to linkrecommendation. The core script userOptions.php comes close to what we need (changing the growthexperiments-homepage-variant user preference), but 1) it acts on all users (or a list), 2) its iteration code is inefficient and probably should not be used in production. So either improve it or write our own.

Event Timeline

Tgr triaged this task as High priority.Jun 1 2021, 9:32 PM
Tgr moved this task from Incoming to Ready for Development on the Growth-Team (Current Sprint) board.
Tgr added a project: Add-Link.
Tgr moved this task from Backlog to Post-release backlog on the Add-Link board.

Change 697835 had a related patch set uploaded (by Gergő Tisza; author: Gergő Tisza):

[mediawiki/core@master] userOptions.php: Properly filter and iterate query

https://gerrit.wikimedia.org/r/697835

Change 697840 had a related patch set uploaded (by Gergő Tisza; author: Gergő Tisza):

[mediawiki/core@master] userOptions.php: allow specifying a user ID range to run on

https://gerrit.wikimedia.org/r/697840

With the patches, the preferences update should be possible with something like

mysql> SELECT MAX(user_id) from user where user_registration < '<experiment start date>';

$ mwscript /vagrant/mediawiki/maintenance/userOptions.php --old control --new linkrecommendation --touserid <id found above> growthexperiments-homepage-variant

@Tgr I've +2'ed these patches, so we could run the script for the target wikis.

This did make me think whether this is going to be sustainable as we roll out to more wikis, but I don't see many good options. It just means we'll have to remember to run this for each wiki as we switch on Add-Link.

Change 697835 merged by jenkins-bot:

[mediawiki/core@master] userOptions.php: Properly filter and iterate query

https://gerrit.wikimedia.org/r/697835

Change 697840 merged by jenkins-bot:

[mediawiki/core@master] userOptions.php: allow specifying a user ID range to run on

https://gerrit.wikimedia.org/r/697840

With the patches, the preferences update should be possible with something like

mysql> SELECT MAX(user_id) from user where user_registration < '<experiment start date>';

$ mwscript /vagrant/mediawiki/maintenance/userOptions.php --old control --new linkrecommendation --touserid <id found above> growthexperiments-homepage-variant

Moving this back into ready for development so that we can run this when @Tgr is around.

https://gerrit.wikimedia.org/r/c/operations/mediawiki-config/+/695364 the start date was around 2021-05-27 12:00 UTC.

wikiadmin@10.192.16.105(testwiki)> select max(user_id) from user;
+--------------+
| max(user_id) |
+--------------+
|        51093 |
+--------------+

wikiadmin@10.192.16.105(testwiki)> select max(user_id) from user where user_registration < '20210526120000';
+--------------+
| max(user_id) |
+--------------+
|        50293 |
+--------------+

wikiadmin@10.192.32.183(testwiki)> select up_value, count(*) from user join user_properties on user_id = up_user and up_property = 'growthexperiments-homepage-variant' where user_id <= 51093 group by up_value;
+--------------------+----------+
| up_value           | count(*) |
+--------------------+----------+
| A                  |        1 |
| C                  |        4 |
| D                  |        5 |
| control            |        5 |
| linkrecommendation |       23 |
+--------------------+----------+

wikiadmin@10.192.32.183(testwiki)> select user_name from user join user_properties on user_id = up_user and up_property = 'growthexperiments-homepage-variant' where up_value = 'control' and user_id <= 51093;
+-----------------------+
| user_name             |
+-----------------------+
| MU test 202106292325  |
| Growthadvancementtest |
| Zilant1k              |
| Mavetuna5             |
| Vincatest7a           |
+-----------------------+
tgr@mwmaint2002:~$ mwscript userOptions.php --wiki=testwiki --old control --new linkrecommendation --touserid 51093 growthexperiments-homepage-variant
Setting growthexperiments-homepage-variant for MU test 202106292325 from 'control' to 'linkrecommendation'
Setting growthexperiments-homepage-variant for Growthadvancementtest from 'control' to 'linkrecommendation'
Setting growthexperiments-homepage-variant for Zilant1k from 'control' to 'linkrecommendation'
Setting growthexperiments-homepage-variant for Mavetuna5 from 'control' to 'linkrecommendation'
Setting growthexperiments-homepage-variant for Vincatest7a from 'control' to 'linkrecommendation'
wikiadmin@10.192.48.84(testwiki)> select user_name from user join user_properties on user_id = up_user and up_property = 'growthexperiments-homepage-variant' where up_value = 'control' and user_id <= 51093;
Empty set (0.00 sec)

Seems to be working correctly. I'll run it on the real wikis on Tuesday.
(Values that are neither control nor linkrecommendation will be interpreted as invalid and the system will fall back to the default value, linkrecommendation, so I don't think there's a need to update them.)

In a more scriptable manner:

for WIKI in testwiki; do mwscript userOptions.php --wiki=$WIKI --old control --new linkrecommendation --touserid `sql $WIKI -- -s -N -e "select max(user_id) from user where user_registration < '20210526120000'"` growthexperiments-homepage-variant; done

Command for production:

for WIKI in `expanddblist /srv/mediawiki-staging/dblists/growthexperiments.dblist`; do mwscript userOptions.php --wiki=$WIKI --nowarn --dry --old control --new linkrecommendation --touserid `sql $WIKI -- -s -N -e "select max(user_id) from user where user_registration < '20210526120000'"` growthexperiments-homepage-variant | tee update-growthexperiments-homepage-variant.$WIKI.log; done

(then verify and repeat without the --dry)

Number of users affected in a dry-run:

$ for FILE in `ls`; do echo $FILE | cut -d'.' -f3 | tr -d '\n'; echo -n ' '; cat $FILE | wc -l | tr -d '\n'; echo -n '; '; done
arwiki 5571
azwiki 0
bgwiki 12
bnwiki 778
cawiki 152
cswiki 741
dawiki 246
dewiki 0
elwiki 167
enwiki 0
eowiki 6
eswiki 13522
etwiki 0
euwiki 121
fawiki 3388
fiwiki 0
frwiki 8071
frwiktionary 95
hewiki 1158
hiwiki 748
hrwiki 174
huwiki 487
hywiki 174
idwiki 1750
jawiki 4078
kawiki 0
kkwiki 0
kowiki 1173
kuwiki 0
ltwiki 0
lvwiki 0
mlwiki 0
mrwiki 0
mswiki 269
nlwiki 0
nowiki 359
plwiki 1402
ptwiki 6875
rowiki 580
ruwiki 5976
shwiki 0
simplewiki 559
skwiki 0
slwiki 0
sqwiki 69
srwiki 278
svwiki 739
tawiki 138
testwiki 0
tewiki 74
thwiki 470
trwiki 3313
ukwiki 905
urwiki 9
viwiki 1923

(largest is eswiki with 13K).

Registration date of the last affected user:

$ for FILE in `find . -mindepth 1 -not -empty`; do WIKI=`echo $FILE | cut -d'.' -f4`; LASTUSER=`tail -n1 $FILE | cut -d' ' -f5- | sed "s/ from 'control' to 'linkrecommendation'//"`; echo -en "$WIKI: \t"; sql $WIKI -- -BN --raw -e "SELECT SUBSTR(user_registration,1,8) FROM user WHERE user_name = '${LASTUSER/\'/}';"; done
arwiki: 	20210526
sqwiki: 	20210526
elwiki: 	20210526
euwiki: 	20210526
ptwiki: 	20210526
srwiki: 	20210526
hewiki: 	20210526
trwiki: 	20210526
urwiki: 	20210526
huwiki: 	20210526
ruwiki: 	20210526
kowiki: 	20210526
rowiki: 	20210526
eowiki: 	20210525
frwiktionary: 	20210526
eswiki: 	20210526
cswiki: 	20210526
nowiki: 	20210526
hiwiki: 	20210526
bgwiki: 	20210526
hywiki: 	20210526
frwiki: 	20210526
simplewiki: 	20210526
mswiki: 	20210526
hrwiki: 	20210526
plwiki: 	20210526
viwiki: 	20210526
ukwiki: 	20210526
fawiki: 	20210526
thwiki: 	20210526
svwiki: 	20210526
cawiki: 	20210526
tewiki: 	20210525
dawiki: 	20210526
bnwiki: 	20210526
idwiki: 	20210526
tawiki: 	20210526
jawiki: 	20210526

Same for the first users:

arwiki: 	20210504
sqwiki: 	20210504
elwiki: 	20180330
euwiki: 	20210504
ptwiki: 	20210504
srwiki: 	20210504
hewiki: 	20210504
trwiki: 	20210504
urwiki: 	20210524
huwiki: 	20210504
ruwiki: 	20210504
kowiki: 	20210504
rowiki: 	20210504
eowiki: 	20210505
frwiktionary: 	20210505
eswiki: 	20210504
cswiki: 	20210504
nowiki: 	20210504
hiwiki: 	20210504
bgwiki: 	20210524
hywiki: 	20210504
frwiki: 	20210503
simplewiki: 	20210504
mswiki: 	20210504
hrwiki: 	20210504
plwiki: 	20210504
viwiki: 	20210504
ukwiki: 	20210504
fawiki: 	20210504
thwiki: 	20210504
svwiki: 	20210504
cawiki: 	20210513
tewiki: 	20210505
dawiki: 	20210504
bnwiki: 	20210504
idwiki: 	20210504
tawiki: 	20210504
jawiki: 	20210504

Seems reasonable, let's do it.

Mentioned in SAL (#wikimedia-operations) [2021-08-12T22:09:53Z] <tgr> T283867 running userOptions.php on Growth wikis as per T283867#7280296

Tgr moved this task from In Progress to QA on the Growth-Team (Current Sprint) board.
Tgr added a subscriber: nettrom_WMF.

This is done. @nettrom_WMF if there's an easy way to double-check that it did not affect users who are part of the experiment, that might be worth doing.

@Tgr : I did some checks on this last Friday and didn't see any indication that this had affected experiment users. Per T277356#7120922, the experiment start timestamp was 2021-05-27T19:12:03Z (which is what I've also used in analyses). From what I could find, there might be a few trailing users that weren't converted. As far as I understand the comments above about how things work, that's not an issue and we can wrap this up?

Thanks for checking @nettrom_WMF! Yeah I don't think we care about a few (probably by now inactive) non-experiment users not getting the feature.