lib/contrast/agent/assess/tracker.rb in contrast-agent-6.4.0 vs lib/contrast/agent/assess/tracker.rb in contrast-agent-6.5.0
- old
+ new
@@ -10,10 +10,11 @@
#
# Finalized objects should run through this class as the Finalizers
# have tightly coupled dependencies on each other.
class Tracker
PROPERTIES_HASH = Contrast::Agent::Assess::Finalizers::Hash.new
+ KEEP_AGE = 600_000.cs__freeze # 10 minutes
class << self
# Retrieve the properties of the given Object, iff they exist.
#
# @param source [Object, nil] the thing for which to look up properties.
@@ -52,9 +53,20 @@
#
# @param source [Object] the instance from which to copy properties
# @param target [Object] the instance to which to copy properties
def copy source, target
PROPERTIES_HASH[target] ||= properties(source).dup
+ end
+
+ # Clean PROPERTIES_HASH of any values older than KEEP_AGE ms or
+ # have nil properties
+ def cleanup!
+ PROPERTIES_HASH.delete_if do |_k, properties|
+ return true if properties.nil?
+ return false unless (event = properties&.event)
+
+ KEEP_AGE <= (Contrast::Utils::Timer.now_ms - event.time)
+ end
end
end
end
end
end