File tree Expand file tree Collapse file tree 4 files changed +23
-6
lines changed
activerecord/lib/active_record/connection_adapters Expand file tree Collapse file tree 4 files changed +23
-6
lines changed Original file line number Diff line number Diff line change @@ -549,14 +549,14 @@ def active?
549
549
# new connection with the database. Implementors should call super if they
550
550
# override the default implementation.
551
551
def reconnect!
552
- clear_cache!
552
+ clear_cache! ( new_connection : true )
553
553
reset_transaction
554
554
end
555
555
556
556
# Disconnects from the database if already connected. Otherwise, this
557
557
# method does nothing.
558
558
def disconnect!
559
- clear_cache!
559
+ clear_cache! ( new_connection : true )
560
560
reset_transaction
561
561
end
562
562
@@ -593,8 +593,16 @@ def throw_away!
593
593
end
594
594
595
595
# Clear any caching the database adapter may be doing.
596
- def clear_cache!
597
- @lock . synchronize { @statements . clear } if @statements
596
+ def clear_cache! ( new_connection : false )
597
+ if @statements
598
+ @lock . synchronize do
599
+ if new_connection
600
+ @statements . reset
601
+ else
602
+ @statements . clear
603
+ end
604
+ end
605
+ end
598
606
end
599
607
600
608
# Returns true if its required to reload the connection between requests for development mode.
Original file line number Diff line number Diff line change @@ -321,23 +321,23 @@ def reload_type_map # :nodoc:
321
321
# Close then reopen the connection.
322
322
def reconnect!
323
323
@lock . synchronize do
324
- super
325
324
@connection . reset
326
325
configure_connection
327
326
reload_type_map
327
+ super
328
328
rescue PG ::ConnectionBad
329
329
connect
330
330
end
331
331
end
332
332
333
333
def reset!
334
334
@lock . synchronize do
335
- clear_cache!
336
335
reset_transaction
337
336
unless @connection . transaction_status == ::PG ::PQTRANS_IDLE
338
337
@connection . query "ROLLBACK"
339
338
end
340
339
@connection . query "DISCARD ALL"
340
+ clear_cache! ( new_connection : true )
341
341
configure_connection
342
342
end
343
343
end
Original file line number Diff line number Diff line change @@ -77,6 +77,8 @@ class SQLite3Adapter < AbstractAdapter
77
77
}
78
78
79
79
class StatementPool < ConnectionAdapters ::StatementPool # :nodoc:
80
+ alias reset clear
81
+
80
82
private
81
83
def dealloc ( stmt )
82
84
stmt . close unless stmt . closed?
Original file line number Diff line number Diff line change @@ -42,6 +42,13 @@ def clear
42
42
cache . clear
43
43
end
44
44
45
+ # Clear the pool without deallocating; this is only safe when we
46
+ # know the server has independently deallocated all statements
47
+ # (e.g. due to a reconnect, or a DISCARD ALL)
48
+ def reset
49
+ cache . clear
50
+ end
51
+
45
52
def delete ( key )
46
53
dealloc cache [ key ]
47
54
cache . delete ( key )
You can’t perform that action at this time.
0 commit comments