Skip to content

Commit

Permalink
[8.0][IMP][mail_tracking] Speed installation time and discard concurr…
Browse files Browse the repository at this point in the history
…ent events (OCA#82)

[IMP] mail_tracking: Speed installation time, discard concurrent events and other fixes
  • Loading branch information
antespi authored and alan196 committed Jun 16, 2023
1 parent df44b4c commit f2816be
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions mail_tracking_mailgun/models/mail_tracking_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,12 @@ def _mailgun_event_type_mapping(self):
'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
Expand All @@ -66,12 +62,12 @@ def _mailgun_signature_verify(self, event):
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')
Expand All @@ -89,8 +85,8 @@ def _db_verify(self, event):
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
Expand Down Expand Up @@ -124,7 +120,7 @@ def _mailgun_metadata(self, mailgun_event_type, event, metadata):
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)),
})
Expand Down

0 comments on commit f2816be

Please sign in to comment.