• Sean McGivern's avatar
    Fix some N+1s when calculating notification recipients · 0206476a
    Sean McGivern authored
    First N+1: we may have loaded a user's notification settings already, but not
    have loaded their sources. Because we're iterating through, we'd potentially
    load sources that are completely unrelated, just because they belong to this
    user.
    
    Second N+1: we do a separate query for each user who could be subscribed to or
    unsubcribed from the target. It's actually more efficient in this case to get
    all subscriptions at once, as we will need to check most of them.
    
    We can fix both by the slightly unpleasant means of checking IDs manually,
    rather than object equality.
    0206476a
user.rb 42.9 KB