diff options
| author | Victor Feyens <vfe@odoo.com> | 2020-12-17 17:24:42 +0000 |
|---|---|---|
| committer | Victor Feyens <vfe@odoo.com> | 2020-12-17 17:24:42 +0000 |
| commit | 10c08157cb152f111bc9df783e15632c52a61b39 (patch) | |
| tree | 394637b4832e27ad01d306f6cd686783b3c7b76e /addons | |
| parent | b23dd1b20fbd656d40e2d8bc4a32a27652e50ee1 (diff) | |
[FIX] calendar_sms: do not clear the cache
in a cron run frequently.
The cron "ir_cron_scheduler_alarm" stores its last run datetime in an
ir.config.parameter. Since modifying config parameters cleans the
cache,
the cron clears the cache every 30 minutes, unless modified...
As the cache is used to improve global system performance, clearing it
frequently should be avoided as much as possible.
Since v13, ir.cron records now store their lastcall datetime, there
is no need to keep the information in a config parameter anymore.
This commit uses this lastcall information instead, as it was done for
the calendar module:
See
https://github.com/odoo/odoo/commit/52645a7b43be157be0782674a0f6b38359293f21
Fixes #63354 for 13+ versions.
For earlier versions (12.0), it cannot be "fixed" since the lastcall
information isn't available (note that the cache clear also happens in
the base calendar method in 12.0).
closes odoo/odoo#63549
X-original-commit: eb02393d2b2b3aee48cfd1d24766ca74bc28fb85
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/calendar_sms/models/calendar.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/addons/calendar_sms/models/calendar.py b/addons/calendar_sms/models/calendar.py index b01e2736f3f..433c72184ef 100644 --- a/addons/calendar_sms/models/calendar.py +++ b/addons/calendar_sms/models/calendar.py @@ -44,9 +44,14 @@ class AlarmManager(models.AbstractModel): """ Cron method, overridden here to send SMS reminders as well """ result = super(AlarmManager, self).get_next_mail() + + cron = self.env.ref('calendar.ir_cron_scheduler_alarm', raise_if_not_found=False) + if not cron: + # Like the super method, do nothing if cron doesn't exist anymore + return result + now = fields.Datetime.to_string(fields.Datetime.now()) - last_sms_cron = self.env['ir.config_parameter'].get_param('calendar_sms.last_sms_cron', default=now) - cron = self.env['ir.model.data'].get_object('calendar', 'ir_cron_scheduler_alarm') + last_sms_cron = cron.lastcall interval_to_second = { "weeks": 7 * 24 * 60 * 60, @@ -64,5 +69,4 @@ class AlarmManager(models.AbstractModel): event_start = fields.Datetime.from_string(event.start) for alert in self.do_check_alarm_for_one_date(event_start, event, max_delta, 0, 'sms', after=last_sms_cron, missing=True): event.browse(alert['event_id'])._do_sms_reminder() - self.env['ir.config_parameter'].set_param('calendar_sms.last_sms_cron', now) return result |
