pull-requests: optimize db transaction logic.
- we've been investigating this issue with locked pull-requests - the transactions arround audit-logs and state-lock seems to be fragile for long-running, and exception prone setups - this change tries to make use of few snapshot transactions to prevent a long ones, and actually try to recover on failed audit-log calls.
This commit is contained in:
parent
8e9be47052
commit
0d36e58be5
2 changed files with 15 additions and 4 deletions
|
|
@ -261,7 +261,6 @@ def store(action, user, action_data=None, user_data=None, ip_addr=None,
|
|||
ip_address = safe_unicode(ip_addr)
|
||||
|
||||
with sa_session.no_autoflush:
|
||||
update_user_last_activity(sa_session, user_id)
|
||||
|
||||
user_log = _store_log(
|
||||
action_name=action_name,
|
||||
|
|
@ -275,11 +274,15 @@ def store(action, user, action_data=None, user_data=None, ip_addr=None,
|
|||
)
|
||||
|
||||
sa_session.add(user_log)
|
||||
if commit:
|
||||
sa_session.commit()
|
||||
entry_id = user_log.entry_id or ''
|
||||
|
||||
update_user_last_activity(sa_session, user_id)
|
||||
|
||||
if commit:
|
||||
sa_session.commit()
|
||||
|
||||
entry_id = user_log.entry_id or ''
|
||||
log.info('AUDIT[%s]: Logging action: `%s` by user:id:%s[%s] ip:%s',
|
||||
entry_id, action_name, user_id, username, ip_address)
|
||||
|
||||
|
|
@ -295,4 +298,6 @@ def update_user_last_activity(sa_session, user_id):
|
|||
log.debug(
|
||||
'updated user `%s` last activity to:%s', user_id, _last_activity)
|
||||
except Exception:
|
||||
log.exception("Failed last activity update")
|
||||
log.exception("Failed last activity update for user_id: %s", user_id)
|
||||
sa_session.rollback()
|
||||
|
||||
|
|
|
|||
|
|
@ -1198,14 +1198,20 @@ class PullRequestModel(BaseModel):
|
|||
pull_request=pull_request,
|
||||
revision=commit_id)
|
||||
|
||||
# initial commit
|
||||
Session().commit()
|
||||
|
||||
if pr_has_changes:
|
||||
# send update email to users
|
||||
try:
|
||||
self.notify_users(pull_request=pull_request, updating_user=updating_user,
|
||||
ancestor_commit_id=ancestor_commit_id,
|
||||
commit_changes=commit_changes,
|
||||
file_changes=file_changes)
|
||||
Session().commit()
|
||||
except Exception:
|
||||
log.exception('Failed to send email notification to users')
|
||||
Session().rollback()
|
||||
|
||||
log.debug(
|
||||
'Updated pull request %s, added_ids: %s, common_ids: %s, '
|
||||
|
|
@ -1221,7 +1227,7 @@ class PullRequestModel(BaseModel):
|
|||
pull_request.pull_request_id, source_ref_id,
|
||||
pull_request.source_ref_parts.commit_id,
|
||||
pull_request_version.pull_request_version_id)
|
||||
Session().commit()
|
||||
|
||||
self.trigger_pull_request_hook(pull_request, pull_request.author, 'update')
|
||||
|
||||
return UpdateResponse(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue