set_cache should invalidate existing related_resultset #110
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In
DBIx::Class::ResultSet::related_resultset, if the current resultset has a cache of results, the rows in that cache are checked for related objects which can be used to populate the cache belonging to the related resultset which is going to be returned.However, the related resultset objects themselves are also stored on
$selfin a cache ($self->{'related_resultsets'}), so that this process is skipped if the related resultset has already been created in a previous call torelated_resultset.This means that if the cache is set after a related resultset has been created, subsequent calls to
related_resultsetretrieve the existing resultset; because it was created before the cache existed, it either has no cache of its own, or has a cache which potentially contradicts the cache in set_cache.There is no user-facing way to 'undo' the creation of a cached related resultset, nor is it obvious from the docs that this might be useful or necessary (not to mention why it should be). In fact, the docs don't even mention that related resultsets are cached.
For example: in this case
$artistis an arrayref of one item:... whereas in this case
$artistisundef:I see two potential solutions:
When
$self->set_cacheis called, clear$self->{'related_resultsets'}. New calls torelated_resultsetwould return new resultsets with the correct cache. Resultsets previously created would be unchanged.When
$self->set_cacheis called, populate the cache for each resultset in$self->{'related_resultsets'}. This may be surprising if those resultsets have also previously populated a cache. Furthermore, what ought to happen if\@cdsdo not all have a populated cache in theirrelated_resultsetfor a given relationship. Should the cache on the existing resultset be emptied, or should it be left alone?I feel that option 1 is the cleanest solution.
This PR introduces: