Skip to content

Commit 9f0b8eb

Browse files
committed
Deprecate Event#{children,parent_of}
1 parent 51e28dc commit 9f0b8eb

File tree

3 files changed

+20
-25
lines changed

3 files changed

+20
-25
lines changed

activesupport/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
* Deprecate `Notification::Event`'s `#children` and `#parent_of?`
2+
13
* Change default serialization format of `MessageEncryptor` from `Marshal` to `JSON` for Rails 7.1.
24

35
Existing apps are provided with an upgrade path to migrate to `JSON` as described in `guides/source/upgrading_ruby_on_rails.md`

activesupport/lib/active_support/notifications/instrumenter.rb

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def unique_id
5656
end
5757

5858
class Event
59-
attr_reader :name, :time, :end, :transaction_id, :children
59+
attr_reader :name, :time, :end, :transaction_id
6060
attr_accessor :payload
6161

6262
def initialize(name, start, ending, transaction_id, payload)
@@ -65,7 +65,6 @@ def initialize(name, start, ending, transaction_id, payload)
6565
@time = start ? start.to_f * 1_000.0 : start
6666
@transaction_id = transaction_id
6767
@end = ending ? ending.to_f * 1_000.0 : ending
68-
@children = []
6968
@cpu_time_start = 0.0
7069
@cpu_time_finish = 0.0
7170
@allocation_count_start = 0
@@ -117,6 +116,23 @@ def allocations
117116
@allocation_count_finish - @allocation_count_start
118117
end
119118

119+
def children # :nodoc:
120+
ActiveSupport::Deprecation.warn <<~EOM
121+
ActiveSupport::Notifications::Event#children is deprecated and will
122+
be removed in Rails 7.2.
123+
EOM
124+
[]
125+
end
126+
127+
def parent_of?(event) # :nodoc:
128+
ActiveSupport::Deprecation.warn <<~EOM
129+
ActiveSupport::Notifications::Event#parent_of? is deprecated and will
130+
be removed in Rails 7.2.
131+
EOM
132+
start = (time - event.time) * 1000
133+
start <= 0 && (start + duration >= event.duration)
134+
end
135+
120136
# Returns the difference in milliseconds between when the execution of the
121137
# event started and when it ended.
122138
#
@@ -133,14 +149,6 @@ def duration
133149
self.end - time
134150
end
135151

136-
def <<(event)
137-
@children << event
138-
end
139-
140-
def parent_of?(event)
141-
@children.include? event
142-
end
143-
144152
private
145153
def now
146154
Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)

activesupport/test/notifications_test.rb

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -462,21 +462,6 @@ def test_events_consumes_information_given_as_payload
462462
assert_equal Hash[payload: :bar], event.payload
463463
end
464464

465-
def test_event_is_parent_based_on_children
466-
time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
467-
468-
parent = event(:foo, Process.clock_gettime(Process::CLOCK_MONOTONIC), Process.clock_gettime(Process::CLOCK_MONOTONIC) + 100, random_id, {})
469-
child = event(:foo, time, time + 10, random_id, {})
470-
not_child = event(:foo, time, time + 100, random_id, {})
471-
472-
parent.children << child
473-
474-
assert parent.parent_of?(child)
475-
assert_not child.parent_of?(parent)
476-
assert_not parent.parent_of?(not_child)
477-
assert_not not_child.parent_of?(parent)
478-
end
479-
480465
def test_subscribe_raises_error_on_non_supported_arguments
481466
notifier = ActiveSupport::Notifications::Fanout.new
482467

0 commit comments

Comments
 (0)