[REF] website: customizable batch/limit on _cron_unlink_old_visitors
In b69917e[1] the cron implementation was changed to unlink old visitors in batches of 1000 records. This was meant to deal with memory/timeout errors when dealing with large amounts of records. However it still searches for records with no limit, which in high record count scenarios and based on instance resources may still generate memory/timeout errors. Technically it could be considered "fine" for the cron to timeout since every batch is committed, so previously unlinked records are not rolled back and the cron should eventually delete them all. However there are some edge cases where memory/time out errors would not be fine, like the cron failing during the first batch, which means no unlink operations would be committed to the database. Errors that are "fine" also generate noise and leave administrators wondering which errors they should ignore and which they should not. It also alarms non-technical customers since after all, they are seeing a reported error. Therefore the search limit and batch size have been added as arguments to the cron. This is completely opt-in since they have the previous values as their defaults. This makes it easy to customize and tune the performance of the job accordingly if required. [1] https://github.com/odoo/odoo/commit/b69917ec0e508f8354d831525c5c48ee79b5967a X-original-commit: e8a4b1f6a239753f66aa827e8e0d67ca4270dba3 Part-of: odoo/odoo#153707
This commit is contained in:
@@ -330,7 +330,7 @@ class WebsiteVisitor(models.Model):
|
||||
self.website_track_ids.visitor_id = target.id
|
||||
self.unlink()
|
||||
|
||||
def _cron_unlink_old_visitors(self):
|
||||
def _cron_unlink_old_visitors(self, batch_size=1000, limit=None):
|
||||
""" Unlink inactive visitors (see '_inactive_visitors_domain' for
|
||||
details).
|
||||
|
||||
@@ -340,8 +340,8 @@ class WebsiteVisitor(models.Model):
|
||||
auto_commit = not getattr(threading.current_thread(), 'testing', False)
|
||||
visitor_model = self.env['website.visitor']
|
||||
for inactive_visitors_batch in split_every(
|
||||
1000,
|
||||
visitor_model.sudo().search(self._inactive_visitors_domain()).ids,
|
||||
batch_size,
|
||||
visitor_model.sudo().search(self._inactive_visitors_domain(), limit=limit).ids,
|
||||
visitor_model.browse,
|
||||
):
|
||||
inactive_visitors_batch.unlink()
|
||||
|
||||
Reference in New Issue
Block a user