Page MenuHomePhabricator

CodeMirror does not set a default for "usecodemirror" preference, causing user_properties bloat
Open, LowPublic1 Estimated Story Points

Description

The CodeMirror extension does not set a default for the usecodemirror preference, causing bloat to the user_properties table.

wikiadmin@10.192.48.133(enwiki)> select count(*), up_value from user_properties where up_property="usecodemirror" group by up_value;
+----------+----------+
| count(*) | up_value |
+----------+----------+
|    54902 | 0        |
|    63037 | 1        |
+----------+----------+
2 rows in set (25.48 sec)

The user_properties table is only supposed to store preference overrides, those that don't match the default. However since there's no default, any time a user changes their preferences, a row has to be saved for usecodemirror. Also, this adds just a bit more to the logged-in user HTML payload because we ship non-default prefs in each request.

A default should be set via extension.json in "DefaultUserOptions". I would suggest that the extension default is set to true (so it works out of the box), but disable it on Wikimedia wikis to maintain the status quo.

This was noticed by @Proc.

Event Timeline

Legoktm triaged this task as High priority.
Restricted Application added a subscriber: Aklapper. · View Herald Transcript

Change 703632 had a related patch set uploaded (by MusikAnimal; author: MusikAnimal):

[mediawiki/extensions/CodeMirror@master] Set default for 'usecodemirror' preference

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

Change 703633 had a related patch set uploaded (by MusikAnimal; author: MusikAnimal):

[operations/mediawiki-config@master] Disable code mirror by default

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

MusikAnimal set the point value for this task to 1.

Due to T286623 and the need to change Core selenium tests to work with CodeMirror, as well as the fact the CodeMIrror API will change in near future (T259059), I've gone with the easy route of having the extension default be false. This matches the status quo, anyway.

Thanks to @Daimona for the help in debugging the tests!

Change 703632 merged by jenkins-bot:

[mediawiki/extensions/CodeMirror@master] Set default for 'usecodemirror' preference

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

dom_walden subscribed.

In the source editor, if I click the "syntax highlighting" button a row gets written to the user_properties table in the database to reflect the CodeMirror feature being enabled for my user. When I click it again, the row is removed.

I have tested this on beta.

I tried to test on production (testwiki), but turns out I cannot. I only have access to replica databases, and these won't show the codemirror property (because it is considered private).

Test Environment: https://en.wikipedia.beta.wmflabs.org CodeMirror 4.0.0 (0332e21) 19:30, 23 July 2021.

Change #1090719 had a related patch set uploaded (by MusikAnimal; author: MusikAnimal):

[mediawiki/extensions/CodeMirror@master] extension.json: set default user option for usecodemirror-colorblind

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

Re-opening as the exact same issue, except for the usecodemirror-colorblind preference:

mysql:research@dbstore1008.eqiad.wmnet [enwiki]> select count(*), up_value from user_properties where up_property="usecodemirror-colorblind" group by up_value;
+----------+----------+
| count(*) | up_value |
+----------+----------+
|   259656 |          |
|   135843 | 0        |
|     3119 | 1        |
+----------+----------+
3 rows in set (1 min 33.299 sec)

I don't know what the blank values are. Maybe something to do with it being a disable-if preference (dependent on usecodemirror)? But anyway, the 0 versus 1 clearly shows we should probably have a default value.
(Related, this preference may later be bundled into a single CodeMirror preference, T359498 T163533).

Change #1090719 merged by jenkins-bot:

[mediawiki/extensions/CodeMirror@master] extension.json: set default user option for usecodemirror-colorblind

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

I'm going to wait to observe changes in data as this is rolled out, before closing again.

I may also create a follow-up task to do a little db cleanup. There must be millions of unneeded rows in user_properties related to CodeMirror across all the dbs.

mysql:research@dbstore1008.eqiad.wmnet [enwiki]> select count(*), up_value from user_properties where up_property="usecodemirror-colorblind" group by up_value;
+----------+----------+
| count(*) | up_value |
+----------+----------+
|   255731 |          |
|   132747 | 0        |
|     3389 | 1        |
+----------+----------+
3 rows in set (1 min 50.306 sec)

The 0s will only get removed when someone toggles the preference, so it's understandable that there are still a lot left. The blank rows are still a mystery. Those keep growing, but I'm less concerned with them because I think eventually usecodemirror-colorblind will be bundled into the codemirror-preferences option.

@Ladsgroup Do you think any db cleanup is necessary here? I've only queried enwiki, but going by that I'd estimate there are maybe around ~1 million rows across all dbs that are safe to delete. Here's the result for usecodemirror as well:

mysql:research@dbstore1008.eqiad.wmnet [enwiki]> select count(*), up_value from user_properties where up_property="usecodemirror" group by up_value;
+----------+----------+
| count(*) | up_value |
+----------+----------+
|    46442 | 0        |
|   108112 | 1        |
+----------+----------+
2 rows in set (37.714 sec)

If requested, I can write a maintenance script.

MusikAnimal lowered the priority of this task from High to Medium.Feb 12 2025, 4:33 PM

The empty string is database conversion of "false" in php. I can try to clean them up next week.

The empty string is database conversion of "false" in php. I can try to clean them up next week.

I haven't forgotten about it. I'm quite busy and this doesn't seem to be a burning problem so I left it for know. Anyone else can take a stab at it!

MusikAnimal lowered the priority of this task from Medium to Low.Apr 8 2025, 7:53 AM