Optimize MembershipManager.memberships_pending_warning()
MembershipManager.memberships_pending_warning() makes a query for a set of members that potentially meet some bounce criteria and then for each member found, it does further processing in Python.
While the first query is pretty fast, the function then makes a further query for each member being checked to look up member.mailing_list. We can easily optimize this by selecting the interval in the original query since the mailinglist table is already part of the JOIN.
On Wikimedia, which had ~2.4k members returned in the first query, this optimization reduced the runtime of memberships_pending_warning() from 26 seconds to 1 second, dramatically speeding up the bounce runner.
Note: I only tested this on MariaDB.
Edited by legoktm