Refactor hydration pattern in DataResource class #3930
Merged
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.
The DataResource class contains a bunch of unnecessary complexity to build objects from database records.
We should build the objects directly from the rows rather than encoding them to JSON and hydrating.
Work here will be limited to removing the hydration pattern from DKAN-scoped classes. This pattern is: serializing objects in order to pass them to other classes or methods only to have them re-hydrated. Where possible, a factory pattern will be implemented to take data without being serialized.
Changes here:
Drupal\common\DataResource
to add a DB record factory method, calledcreateFromRecord()
.Drupal\metastore\ResourceMapper
to use the newDataResource
factory method, rather than a hydration round-trip.DataResource::createCommon()
to be inlined into the methods that call it. We do this because adding the factory method caused CodeClimate to complain about too many methods, so we remove this one.fixes WCMS-14059