[FIX] mass_mailing: speed up recipients filtering

Using a `set` to lookup recipients that already received an email is
much faster on average than with a list. `x in list` is O(n) on
average, whereas `x in set` closer to O(1) on average.

Example: for a sample mailing with 50k recipients that is half-through,
filtering the remaining half (25k) took 10s with a list, and 1s with
the set.

X-original-commit: 7948698cc6e6b0af5fc84847ea7ec166882eda0b
This commit is contained in:
Olivier Dony
2020-09-05 04:34:13 +00:00
parent 9d77062ddb
commit d6e734d436
+1 -1
View File
@@ -536,7 +536,7 @@ class MassMailing(models.Model):
('model', '=', self.mailing_model_real),
('res_id', 'in', res_ids),
('mass_mailing_id', '=', self.id)], ['res_id'])
done_res_ids = [record['res_id'] for record in already_mailed]
done_res_ids = {record['res_id'] for record in already_mailed}
return [rid for rid in res_ids if rid not in done_res_ids]
def _get_unsubscribe_url(self, email_to, res_id):