Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor hydration pattern in DataResource class #3930

Merged
merged 11 commits into from
Apr 19, 2023
Merged

Refactor hydration pattern in DataResource class #3930

merged 11 commits into from
Apr 19, 2023

Conversation

paul-m
Copy link
Contributor

@paul-m paul-m commented Mar 30, 2023

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:

  • Modify Drupal\common\DataResource to add a DB record factory method, called createFromRecord().
  • Modify Drupal\metastore\ResourceMapper to use the new DataResource factory method, rather than a hydration round-trip.
  • Remove various references to the hydration pattern in other classes.
  • Refactor 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.
  • Some CS improvements.

fixes WCMS-14059

  • Test coverage exists

@paul-m paul-m marked this pull request as ready for review April 17, 2023 17:15
@paul-m paul-m requested a review from dafeder April 18, 2023 19:36
Copy link
Member

@dafeder dafeder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See two questions - otherwise looks great!

modules/common/tests/src/Unit/DataResourceTest.php Outdated Show resolved Hide resolved
modules/common/tests/src/Unit/DataResourceTest.php Outdated Show resolved Hide resolved
@dafeder dafeder changed the title 14059 refactor hydration pattern Refactor hydration pattern in DataResource class Apr 19, 2023
@dafeder dafeder merged commit 1e56fa4 into 2.x Apr 19, 2023
@dafeder dafeder deleted the 14059-dehydrate branch April 19, 2023 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants