Create a per-user cache of suggested edits tasks, populate it on user creation, and refresh it each time tasks are fetched (via visits to Special:Homepage or through toggling task/topic filters).
This would optimize the loading of Special:Homepage, and not the in-module interactions (toggling difficulty / topic filters). Improved performance when toggling filters will in part be handled by T242560.
The approach would be roughly:
- user creates account and is opted into the experiment, in the same request we make a request to get a set of suggested edits (as if they had visited Special:Homepage and opted in to suggested edits, so we'd use the default values of copyedit+links and no topics) and cache it for that user for 30 days
- when the user visits Special:Homepage, the code which fetches suggested edits first looks to see if there is data in the cache for the current set of filters (e.g. copyedit+links), and if so loads it, if not it asks ElasticSearch for it. After getting it from ElasticSearch, we cache it again for 30 days.
- When the user requests tasks, use a DB query to validate that the relevant maintenance templates are still present in the cached tasks; remove tasks from the cache which no longer have the maintenance templates
- on each change to the users task/topic filter preferences, recache the data