mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Little things:
- Retries on deadlock when calculating average time - Removes Warning: When specifying html format for errors - Doesn't use manual SQL to update user's ip address
This commit is contained in:
@@ -15,6 +15,24 @@ class ActiveRecord::Base
|
||||
ActiveRecord::Base.exec_sql(*args)
|
||||
end
|
||||
|
||||
|
||||
# Executes the given block +retries+ times (or forever, if explicitly given nil),
|
||||
# catching and retrying SQL Deadlock errors.
|
||||
#
|
||||
# Thanks to: http://stackoverflow.com/a/7427186/165668
|
||||
#
|
||||
def self.retry_lock_error(retries=5, &block)
|
||||
begin
|
||||
yield
|
||||
rescue ActiveRecord::StatementInvalid => e
|
||||
if e.message =~ /Deadlock found when trying to get lock/ and (retries.nil? || retries > 0)
|
||||
retry_lock_error(retries ? retries - 1 : nil, &block)
|
||||
else
|
||||
raise e
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Support for psql. If we want to support multiple RDBMs in the future we can
|
||||
# split this.
|
||||
def exec_sql_row_count(*args)
|
||||
|
||||
Reference in New Issue
Block a user