[FIX] google_(account|calendar): Concurrent Synchro
Each time the calendar view of event.calendar is loaded, the synchronization with google calendar was launched and if a user open many tabs, it can lead to deadlock Solution: Check for lock before launching the synchro, if the transaction cannot acquire the lock, it's proably because another synchro already started closes odoo/odoo#69540 X-original-commit: 101598fae6fc32a49bb6d422a82b621a81201cb5 Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
This commit is contained in:
@@ -146,14 +146,14 @@ class GoogleService(models.AbstractModel):
|
||||
res.raise_for_status()
|
||||
status = res.status_code
|
||||
|
||||
if int(status) in (204, 404): # Page not found, no response
|
||||
if int(status) == 204: # Page not found, no response
|
||||
response = False
|
||||
else:
|
||||
response = res.json()
|
||||
|
||||
try:
|
||||
ask_time = datetime.strptime(res.headers.get('date'), "%a, %d %b %Y %H:%M:%S %Z")
|
||||
except:
|
||||
ask_time = datetime.strptime(res.headers.get('date', ''), "%a, %d %b %Y %H:%M:%S %Z")
|
||||
except ValueError:
|
||||
pass
|
||||
except requests.HTTPError as error:
|
||||
if error.response.status_code in (204, 404):
|
||||
|
||||
@@ -97,6 +97,14 @@ class User(models.Model):
|
||||
self.ensure_one()
|
||||
if self.google_synchronization_stopped:
|
||||
return False
|
||||
|
||||
# don't attempt to sync when another sync is already in progress, as we wouldn't be
|
||||
# able to commit the transaction anyway (row is locked)
|
||||
self.env.cr.execute("""SELECT id FROM res_users WHERE id = %s FOR NO KEY UPDATE SKIP LOCKED""", [self.id])
|
||||
if not self.env.cr.rowcount:
|
||||
_logger.info("skipping calendar sync, locked user %s", self.login)
|
||||
return False
|
||||
|
||||
full_sync = not bool(self.google_calendar_sync_token)
|
||||
with google_calendar_token(self) as token:
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user