Move with_timeout / without_timeout to ApplicationRecord.
This commit is contained in:
@@ -10,7 +10,7 @@ class BulkRevert
|
|||||||
ModAction.log("Processed bulk revert for #{constraints.inspect} by #{creator.name}")
|
ModAction.log("Processed bulk revert for #{constraints.inspect} by #{creator.name}")
|
||||||
|
|
||||||
CurrentUser.scoped(creator) do
|
CurrentUser.scoped(creator) do
|
||||||
ActiveRecord::Base.without_timeout do
|
ApplicationRecord.without_timeout do
|
||||||
find_post_versions.order("updated_at, id").each do |version|
|
find_post_versions.order("updated_at, id").each do |version|
|
||||||
version.undo!
|
version.undo!
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -9,37 +9,37 @@ module Moderator
|
|||||||
end
|
end
|
||||||
|
|
||||||
def artists
|
def artists
|
||||||
ActiveRecord::Base.without_timeout do
|
ApplicationRecord.without_timeout do
|
||||||
Queries::Artist.all(min_date, max_level)
|
Queries::Artist.all(min_date, max_level)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def comments
|
def comments
|
||||||
ActiveRecord::Base.without_timeout do
|
ApplicationRecord.without_timeout do
|
||||||
Queries::Comment.all(min_date, max_level)
|
Queries::Comment.all(min_date, max_level)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def mod_actions
|
def mod_actions
|
||||||
ActiveRecord::Base.without_timeout do
|
ApplicationRecord.without_timeout do
|
||||||
Queries::ModAction.all
|
Queries::ModAction.all
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def notes
|
def notes
|
||||||
ActiveRecord::Base.without_timeout do
|
ApplicationRecord.without_timeout do
|
||||||
Queries::Note.all(min_date, max_level)
|
Queries::Note.all(min_date, max_level)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def appeals
|
def appeals
|
||||||
ActiveRecord::Base.without_timeout do
|
ApplicationRecord.without_timeout do
|
||||||
Queries::PostAppeal.all(min_date)
|
Queries::PostAppeal.all(min_date)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def flags
|
def flags
|
||||||
ActiveRecord::Base.without_timeout do
|
ApplicationRecord.without_timeout do
|
||||||
Queries::PostFlag.all(min_date)
|
Queries::PostFlag.all(min_date)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -49,19 +49,19 @@ module Moderator
|
|||||||
end
|
end
|
||||||
|
|
||||||
def posts
|
def posts
|
||||||
ActiveRecord::Base.without_timeout do
|
ApplicationRecord.without_timeout do
|
||||||
Queries::Upload.all(min_date, max_level)
|
Queries::Upload.all(min_date, max_level)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def user_feedbacks
|
def user_feedbacks
|
||||||
ActiveRecord::Base.without_timeout do
|
ApplicationRecord.without_timeout do
|
||||||
Queries::UserFeedback.all
|
Queries::UserFeedback.all
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def wiki_pages
|
def wiki_pages
|
||||||
ActiveRecord::Base.without_timeout do
|
ApplicationRecord.without_timeout do
|
||||||
Queries::WikiPage.all(min_date, max_level)
|
Queries::WikiPage.all(min_date, max_level)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -43,6 +43,29 @@ class ApplicationRecord < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
concerning :ActiveRecordExtensions do
|
||||||
|
class_methods do
|
||||||
|
def without_timeout
|
||||||
|
connection.execute("SET STATEMENT_TIMEOUT = 0") unless Rails.env == "test"
|
||||||
|
yield
|
||||||
|
ensure
|
||||||
|
connection.execute("SET STATEMENT_TIMEOUT = #{CurrentUser.user.try(:statement_timeout) || 3_000}") unless Rails.env == "test"
|
||||||
|
end
|
||||||
|
|
||||||
|
def with_timeout(n, default_value = nil, new_relic_params = {})
|
||||||
|
connection.execute("SET STATEMENT_TIMEOUT = #{n}") unless Rails.env == "test"
|
||||||
|
yield
|
||||||
|
rescue ::ActiveRecord::StatementInvalid => x
|
||||||
|
if Rails.env.production?
|
||||||
|
NewRelic::Agent.notice_error(x, :custom_params => new_relic_params.merge(:user_id => CurrentUser.id, :user_ip_addr => CurrentUser.ip_addr))
|
||||||
|
end
|
||||||
|
return default_value
|
||||||
|
ensure
|
||||||
|
connection.execute("SET STATEMENT_TIMEOUT = #{CurrentUser.user.try(:statement_timeout) || 3_000}") unless Rails.env == "test"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
concerning :PostgresExtensions do
|
concerning :PostgresExtensions do
|
||||||
class_methods do
|
class_methods do
|
||||||
def columns(*params)
|
def columns(*params)
|
||||||
|
|||||||
@@ -3,27 +3,6 @@ module Danbooru
|
|||||||
module ActiveRecord
|
module ActiveRecord
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
module ClassMethods
|
|
||||||
def without_timeout
|
|
||||||
connection.execute("SET STATEMENT_TIMEOUT = 0") unless Rails.env == "test"
|
|
||||||
yield
|
|
||||||
ensure
|
|
||||||
connection.execute("SET STATEMENT_TIMEOUT = #{CurrentUser.user.try(:statement_timeout) || 3_000}") unless Rails.env == "test"
|
|
||||||
end
|
|
||||||
|
|
||||||
def with_timeout(n, default_value = nil, new_relic_params = {})
|
|
||||||
connection.execute("SET STATEMENT_TIMEOUT = #{n}") unless Rails.env == "test"
|
|
||||||
yield
|
|
||||||
rescue ::ActiveRecord::StatementInvalid => x
|
|
||||||
if Rails.env.production?
|
|
||||||
NewRelic::Agent.notice_error(x, :custom_params => new_relic_params.merge(:user_id => CurrentUser.id, :user_ip_addr => CurrentUser.ip_addr))
|
|
||||||
end
|
|
||||||
return default_value
|
|
||||||
ensure
|
|
||||||
connection.execute("SET STATEMENT_TIMEOUT = #{CurrentUser.user.try(:statement_timeout) || 3_000}") unless Rails.env == "test"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
%w(execute select_value select_values select_all).each do |method_name|
|
%w(execute select_value select_values select_all).each do |method_name|
|
||||||
define_method("#{method_name}_sql") do |sql, *params|
|
define_method("#{method_name}_sql") do |sql, *params|
|
||||||
self.class.connection.__send__(method_name, self.class.sanitize_sql_array([sql, *params]))
|
self.class.connection.__send__(method_name, self.class.sanitize_sql_array([sql, *params]))
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class AddCreatedAtIndexToVersions < ActiveRecord::Migration
|
class AddCreatedAtIndexToVersions < ActiveRecord::Migration
|
||||||
def change
|
def change
|
||||||
ActiveRecord::Base.without_timeout do
|
ApplicationRecord.without_timeout do
|
||||||
add_index :note_versions, :created_at
|
add_index :note_versions, :created_at
|
||||||
add_index :artist_versions, :created_at
|
add_index :artist_versions, :created_at
|
||||||
add_index :wiki_page_versions, :created_at
|
add_index :wiki_page_versions, :created_at
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class AddForumPostIdToTagRequests < ActiveRecord::Migration
|
class AddForumPostIdToTagRequests < ActiveRecord::Migration
|
||||||
def change
|
def change
|
||||||
ActiveRecord::Base.without_timeout do
|
ApplicationRecord.without_timeout do
|
||||||
add_column :tag_aliases, :forum_post_id, :integer
|
add_column :tag_aliases, :forum_post_id, :integer
|
||||||
add_column :tag_implications, :forum_post_id, :integer
|
add_column :tag_implications, :forum_post_id, :integer
|
||||||
add_column :bulk_update_requests, :forum_post_id, :integer
|
add_column :bulk_update_requests, :forum_post_id, :integer
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class AddUniqueNameConstraintToUsers < ActiveRecord::Migration
|
class AddUniqueNameConstraintToUsers < ActiveRecord::Migration
|
||||||
def up
|
def up
|
||||||
ActiveRecord::Base.without_timeout do
|
User.without_timeout do
|
||||||
remove_index :users, :name
|
remove_index :users, :name
|
||||||
execute "create unique index index_users_on_name on users(lower(name))"
|
execute "create unique index index_users_on_name on users(lower(name))"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment'))
|
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment'))
|
||||||
|
|
||||||
ActiveRecord::Base.without_timeout do
|
ArtistUrl.without_timeout do
|
||||||
ArtistUrl.where("normalized_url like ?", "\%nicovideo\%").find_each do |url|
|
ArtistUrl.where("normalized_url like ?", "\%nicovideo\%").find_each do |url|
|
||||||
before = url.normalized_url
|
before = url.normalized_url
|
||||||
url.normalize
|
url.normalize
|
||||||
|
|||||||
Reference in New Issue
Block a user