From 1c62dbdd8271a5fe4c92abdbfb9f07dc9d830a12 Mon Sep 17 00:00:00 2001 From: Antonio Espinosa Date: Fri, 9 Sep 2016 13:29:58 +0200 Subject: [PATCH] [8.0][IMP][mail_tracking] Speed installation time and discard concurrent events (#82) [IMP] mail_tracking: Speed installation time, discard concurrent events and other fixes --- .../models/mail_tracking_email.py | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/mail_tracking_mailgun/models/mail_tracking_email.py b/mail_tracking_mailgun/models/mail_tracking_email.py index ebd7d658..f7008ed7 100644 --- a/mail_tracking_mailgun/models/mail_tracking_email.py +++ b/mail_tracking_mailgun/models/mail_tracking_email.py @@ -42,16 +42,12 @@ class MailTrackingEmail(models.Model): 'dropped': 'reject', } - @property - def _mailgun_supported_event_types(self): - return self._mailgun_event_type_mapping.keys() - def _mailgun_event_type_verify(self, event): event = event or {} mailgun_event_type = event.get('event') - if mailgun_event_type not in self._mailgun_supported_event_types: - _logger.info("Mailgun: event type '%s' not supported", - mailgun_event_type) + if mailgun_event_type not in self._mailgun_event_type_mapping: + _logger.error("Mailgun: event type '%s' not supported", + mailgun_event_type) return False # OK, event type is valid return True @@ -66,12 +62,12 @@ class MailTrackingEmail(models.Model): event = event or {} api_key = self.env['ir.config_parameter'].get_param('mailgun.apikey') if not api_key: - _logger.info("No Mailgun api key configured. " - "Please add 'mailgun.apikey' to System parameters " - "to enable Mailgun authentication webhoook requests. " - "More info at: " - "https://documentation.mailgun.com/user_manual.html" - "#webhooks") + _logger.warning("No Mailgun api key configured. " + "Please add 'mailgun.apikey' to System parameters " + "to enable Mailgun authentication webhoook " + "requests. More info at: " + "https://documentation.mailgun.com/" + "user_manual.html#webhooks") else: timestamp = event.get('timestamp') token = event.get('token') @@ -89,8 +85,8 @@ class MailTrackingEmail(models.Model): odoo_db = event.get('odoo_db') current_db = self.env.cr.dbname if odoo_db != current_db: - _logger.info("Mailgun: Database '%s' is not the current database", - odoo_db) + _logger.error("Mailgun: Database '%s' is not the current database", + odoo_db) return False # OK, DB is current return True @@ -124,7 +120,7 @@ class MailTrackingEmail(models.Model): metadata[k] = event[v] # Special field mapping metadata.update({ - 'mobile': event.get('device-type') in ('mobile', 'tablet'), + 'mobile': event.get('device-type') in {'mobile', 'tablet'}, 'user_country_id': self._country_search( event.get('country', False)), })