appcanary / coalmine

GNU Lesser General Public License v3.0
0 stars 0 forks source link

Speed up email query #359

Open mveytsman opened 6 years ago

mveytsman commented 6 years ago

@phillmv the query you asked me to look at came from the EmailManager which found every user that had outstanding notifications that wanted them before building a vuln/patched email for each of those users.

In building the email, we query the notifications table again for each account:

unnotified_logs = VulnQuery.new(acct).unnotified_vuln_logs.where("log_bundle_vulnerabilities.created_at >= ? ", 2.days.ago)
# ...
if unnotified_logs.any?
        email = EmailVulnerable.create!(:account => acct)

Seeing that, it seems like the fastest fix here is to just get rid of the the slow query that tries to guess which accounts have notifications to send and just do the faster query (scoped to the last 2 days of events) for every account.

Can you sanity check this?