Fix bugs where config.when_first_matching_example_defined hooks would fire multiple times
Created by: yujinakayama
The config.when_first_matching_example_defined
hooks are registered on @derived_metadata_blocks
, which is an instance of FilterableItemRepository::QueryOptimized
, and unregistered on the first invocation, so that they won't run multiple times.
However, they are actually unregistered only from the internal memoized cache for a particular metadata in FilterableItemRepository::QueryOptimized
. As a result, the hooks would be invoked multiple times in the following cases:
- When the memoized cache is not used. In particular, when the value of the hook's metadata is a
Proc
. - When the hooks are memoized in combination with another registered metadata before the first invocation.
To fix these bugs, we need to properly unregister the hook from the original hook collection (@items_and_filters
in FilterableItemRepository::QueryOptimized
) rather than the memoized cache.