File tree 1 file changed +10
-9
lines changed
1 file changed +10
-9
lines changed Original file line number Diff line number Diff line change @@ -45,15 +45,17 @@ class << self
45
45
def examine ( payload , sql :)
46
46
return unless ( examiner = build_examiner )
47
47
48
- if AppMap . explain_queries? && examiner . in_transaction? && examiner . database_type == :postgres
48
+ in_transaction = examiner . in_transaction?
49
+
50
+ if AppMap . explain_queries? && examiner . database_type == :postgres
49
51
if sql =~ /\A (SELECT|INSERT|UPDATE|DELETE|WITH)/i
50
52
savepoint_established = \
51
53
begin
52
- examiner . execute_query 'SAVEPOINT appmap_sql_examiner'
54
+ tx_query = in_transaction ? 'SAVEPOINT appmap_sql_examiner' : 'BEGIN TRANSACTION'
55
+ examiner . execute_query tx_query
53
56
true
54
57
rescue
55
58
# Probably: Sequel::DatabaseError: PG::InFailedSqlTransaction
56
- byebug
57
59
warn $!
58
60
false
59
61
end
@@ -62,13 +64,12 @@ def examine(payload, sql:)
62
64
plan = nil
63
65
begin
64
66
plan = examiner . execute_query ( %(EXPLAIN #{ sql } ) )
65
- rescue
66
- warn "Exception occurred explaining query: #{ $!} "
67
- examiner . execute_query 'ROLLBACK TO SAVEPOINT appmap_sql_examiner'
68
- end
69
- if plan
70
67
payload [ :query_plan ] = plan . map { |line | line [ :'QUERY PLAN' ] } . join ( "\n " )
71
- examiner . execute_query 'RELEASE SAVEPOINT appmap_sql_examiner'
68
+ rescue
69
+ warn "(appmap) Error explaining query: #{ $!} "
70
+ ensure
71
+ tx_query = in_transaction ? 'ROLLBACK TO SAVEPOINT appmap_sql_examiner' : 'ROLLBACK'
72
+ examiner . execute_query tx_query
72
73
end
73
74
end
74
75
end
You can’t perform that action at this time.
0 commit comments