Use exec_query
for custom SQL execution
Also align how we use query Postgres from controllers. The change is mainly due to regular (but not reproducible) issues with the `intervalstyle` defaulting to `postgres` (instead of `iso8601`) and thereby causing issues. We're just experimenting to see whether this change resolves the issue.
This commit is contained in:
@ -60,7 +60,7 @@ class CommunitySolutionsController < ApplicationController
|
||||
|
||||
# Acquire lock here! This is expensive but required for synchronization
|
||||
@community_solution_lock = ActiveRecord::Base.transaction do
|
||||
ActiveRecord::Base.connection.execute("LOCK #{CommunitySolutionLock.table_name} IN ACCESS EXCLUSIVE MODE")
|
||||
ApplicationRecord.connection.exec_query("LOCK #{CommunitySolutionLock.table_name} IN ACCESS EXCLUSIVE MODE")
|
||||
|
||||
lock = CommunitySolutionLock.where(user: current_user, community_solution: @community_solution).order(locked_until: :asc).last
|
||||
|
||||
|
@ -90,7 +90,7 @@ module RedirectBehavior
|
||||
|
||||
# Acquire lock here! This is expensive but required for synchronization
|
||||
@community_solution_lock = ActiveRecord::Base.transaction do
|
||||
ActiveRecord::Base.connection.execute("LOCK #{CommunitySolutionLock.table_name} IN ACCESS EXCLUSIVE MODE")
|
||||
ApplicationRecord.connection.exec_query("LOCK #{CommunitySolutionLock.table_name} IN ACCESS EXCLUSIVE MODE")
|
||||
|
||||
# This is returned
|
||||
CommunitySolutionLock.find_or_create_by(community_solution: @community_solution, locked_until: Time.zone.now...) do |lock|
|
||||
|
@ -107,7 +107,7 @@ class ExecutionEnvironmentsController < ApplicationController
|
||||
working_time_statistics = {}
|
||||
user_statistics = {}
|
||||
|
||||
ApplicationRecord.connection.execute(working_time_query).each do |tuple|
|
||||
ApplicationRecord.connection.exec_query(working_time_query).each do |tuple|
|
||||
tuple = tuple.merge({
|
||||
'average_time' => format_time_difference(tuple['average_time']),
|
||||
'stddev_time' => format_time_difference(tuple['stddev_time']),
|
||||
@ -115,7 +115,7 @@ class ExecutionEnvironmentsController < ApplicationController
|
||||
working_time_statistics[tuple['exercise_id'].to_i] = tuple
|
||||
end
|
||||
|
||||
ApplicationRecord.connection.execute(user_query).each do |tuple|
|
||||
ApplicationRecord.connection.exec_query(user_query).each do |tuple|
|
||||
user_statistics[tuple['exercise_id'].to_i] = tuple
|
||||
end
|
||||
|
||||
|
@ -69,7 +69,7 @@ class ExternalUsersController < ApplicationController
|
||||
|
||||
statistics = {}
|
||||
|
||||
ApplicationRecord.connection.execute(working_time_query(tag&.id)).each do |tuple|
|
||||
ApplicationRecord.connection.exec_query(working_time_query(tag&.id)).each do |tuple|
|
||||
tuple = tuple.merge('working_time' => format_time_difference(tuple['working_time']))
|
||||
statistics[tuple['exercise_id'].to_i] = tuple
|
||||
end
|
||||
|
@ -16,7 +16,7 @@ class PingController < ApplicationController
|
||||
|
||||
def postgres_connected!
|
||||
# any unhandled exception leads to a HTTP 500 response.
|
||||
return if ApplicationRecord.connection.execute('SELECT 1 as result').first['result'] == 1
|
||||
return if ApplicationRecord.connection.exec_query('SELECT 1 as result').first['result'] == 1
|
||||
|
||||
raise ActiveRecord::ConnectionNotEstablished
|
||||
end
|
||||
|
Reference in New Issue
Block a user