[FIX] website : prevent bad query
In database with front end, there are lot of bad query like this: bad query: UPDATE "website_visitor" SET "timezone"='Europe/Paris',"write_uid"=116,"write_date"=(now() at time zone 'UTC') WHERE id IN (15414) closes odoo/odoo#70709 Error: Could not serialize access due to concurrent update X-original-commit: d0db984990679a63714ca62e6b605d94af7d5c28 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
committed by
Thibault Delavallée
parent
89f9649d6b
commit
1e764eb2b2
@@ -192,7 +192,7 @@ class WebsiteVisitor(models.Model):
|
||||
if visitor and not visitor.timezone:
|
||||
tz = self._get_visitor_timezone()
|
||||
if tz:
|
||||
visitor.timezone = tz
|
||||
visitor._update_visitor_timezone(tz)
|
||||
if not visitor and force_create:
|
||||
visitor = self._create_visitor()
|
||||
|
||||
@@ -292,6 +292,17 @@ class WebsiteVisitor(models.Model):
|
||||
visitors_to_archive = self.env['website.visitor'].sudo().search([('last_connection_datetime', '<', deadline)])
|
||||
visitors_to_archive.write({'active': False})
|
||||
|
||||
def _update_visitor_timezone(self, timezone):
|
||||
""" We need to do this part here to avoid concurrent updates error. """
|
||||
try:
|
||||
with self.env.cr.savepoint():
|
||||
query_lock = "SELECT * FROM website_visitor where id = %s FOR NO KEY UPDATE NOWAIT"
|
||||
self.env.cr.execute(query_lock, (self.id,), log_exceptions=False)
|
||||
query = "UPDATE website_visitor SET timezone = %s WHERE id = %s"
|
||||
self.env.cr.execute(query, (timezone, self.id), log_exceptions=False)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def _update_visitor_last_visit(self):
|
||||
""" We need to do this part here to avoid concurrent updates error. """
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user