As part of T321527: Support conditional defaults for user properties, the Growth-Team is working on adding support for conditional user defaults (in the first iteration, based on user_registration only). In this task, we should make use of conditional user defaults in the Echo codebase.
During this process, we need to be cautious about users who currently have the defaults set. In the database, using the default user property value is represented as "nothing is written in the database" and as such, if we change the default value, we need to add rows for users where there previously were no records.
Within this task, we should replace the majority of user_properties rows for the following properties (properties inserted in Hooks:: getNewUserPreferenceOverrides for all new users in Echo) with conditional defaults:
- echo-subscriptions-web-reverted
- echo-subscriptions-web-article-linked
- echo-subscriptions-email-mention
- echo-subscriptions-email-article-linked
For more details, see T54777#9139837 and T333531#8778414.
This logic was introduced in April 2013 in this patch.
New scope of task
After the original deployment plan did not succeed (see below and T353225#9520336), Growth team decided to stop new rows from getting created (handled within this task). Dropping the legacy rows was split to T357072: Echo: Drop droppable rows from user_properties.
Original deployment plan
One of the complexities associated with the deployment lies with the fact that changing user property defaults affects all users that do not have a specific row in user_properties. This can be resolved by temporarily inserting rows to user_properties for all post-2013 users (so that the default values are not actually used). Unfortunately, that is not easily possible, because UserOptionsManager automatically drops rows from user_properties if they happen to match the current default.
To workaround that, we can make use of the fact that all of the affected properties (see above) are booleans and that true/false can be constructed by casting specific integers or strings (eg. (bool)2 evaluating to true etc.). This is possible, because both usages of the properties (Special:Preferences and Echo itself) do not really care whether the user option is true or false; they only care about their truthiness/falsiness when casted to a bool.
In this plan, I decided to go with 0 to represent false and 2 to represent true.
Implementation-wise, we would:
- In WMF config, set the default for echo-subscriptions-web-reverted to 2 (as its current default is true) and the default for echo-subscriptions-web-article-linked, echo-subscriptions-email-mention and echo-subscriptions-email-article-linked to '' (as their current default is false). This should not have any impact other than rows being inserted for all users.
- Run userOptions.php and ensure all users that registered post-2013 (when the change of defaults happened) have rows in user_properties
- Requires T354417: userOptions.php cannot be used to change user options from default to a new value to be resolved first
- Once the task gets resolved, we'd run commands like the following (and similar):
- foreachwiki userOptions.php --old-is-default --old=2 --new 1 --nowarn --dry 'echo-subscriptions-web-reverted'
- foreachwiki userOptions.php --old-is-default --old=0 --new '' --nowarn --dry 'echo-subscriptions-web-article-linked'
- Verify no users have missing user_properties rows by running a SQL query, such as select user_name from user where user_id not in (select up_user from user_properties where up_property='echo-subscriptions-web-reverted');.
- Enable conditional defaults for echo properties and drop the temporary defaults overrides from step 1
- Backup the user_properties table.
- Drop all the now-redundant rows (ie. rows where the up_value matches the now-default).
For enwiki, the above plan should be executed per-property (eg. do one property first, clean-up, and then move to the next), in order to avoid creating an extremely large table.
We should also verify the plan's viability at beta-cluster and testwiki first.
QA Testing notes:
- We should test to ensure that nothing changes and that new users created still have echo-subscriptions-web-reverted set to false and echo-subscriptions-web-article-linked, echo-subscriptions-email-mention and echo-subscriptions-email-article-linked to true.
- Comparison testing: Test accounts that registered prior to February 2024 (when conditional defaults were deployed) and a newly created account.