These are the last two queries seriously affecting performance. One was being generated by sequalize and I converted that to a raw query, which also required some small changes to variable names for pendingAccounts.
Both queries were running for over 30 seconds on a test db with only around 20k registrations, now they return in under 500ms. No more WARN: process event overlap within PROCESS_EVENTS_MS 10000 errors. For the most part the optimizations are using common table expressions to reduce looping and the number of full table scans.
These are the last two queries seriously affecting performance. One was being generated by sequalize and I converted that to a raw query, which also required some small changes to variable names for pendingAccounts.
Both queries were running for over 30 seconds on a test db with only around 20k registrations, now they return in under 500ms. No more
WARN: process event overlap within PROCESS_EVENTS_MS 10000
errors. For the most part the optimizations are using common table expressions to reduce looping and the number of full table scans.