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

Fix loose typing of constructor for transaction level, and remove public property. #22535

Merged
merged 13 commits into from
Sep 6, 2024

Conversation

caddoo
Copy link
Contributor

@caddoo caddoo commented Aug 28, 2024

Description:

This is a possible first step to fix the problem with the very loosely typed dependency that the TransactionLevel class has.

This also removes that nasty public property $supportsUncommitted; and introduces some encapsulation for that concept.

The problem is identifying a common interface between:

  • \Piwik\Tracker\Db
  • \Piwik\Db\AdapterInterface
  • \Piwik\Db

There are of course fetchOne query, however some classes have them statically and others not, so an interface isn't possible.

My idea/solution does cause a little duplication, but I think having:

  • Type safety
  • Consistency
  • Readability

Is more important here.

Review

@caddoo caddoo force-pushed the better-transaction-level-interface branch from b1cdf57 to dcb4b94 Compare September 3, 2024 09:40
@caddoo caddoo changed the title WIP - Fix loose typing of constructor for transaction level, and remove public property. Fix loose typing of constructor for transaction level, and remove public property. Sep 3, 2024
@caddoo caddoo requested a review from a team September 4, 2024 03:13
@caddoo caddoo added Needs Review PRs that need a code review not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org. labels Sep 4, 2024
@caddoo caddoo marked this pull request as ready for review September 4, 2024 03:13
Copy link
Contributor

@michalkleiner michalkleiner left a comment

Choose a reason for hiding this comment

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

In general the changes look good, I've got a few suggestions for better consistency and perhaps less code:

  • keep the order of the methods in the interface consistent in order of get/set for a property, then get/set for the other. Now it's get/set/set/get.
  • consider using a trait as the implementation of the four methods is identical across 4 classes. If other db schemas need different implementation they can opt to not use the trait and implement the methods directly.

If someone else feels like we shouldn't use a trait here I'd be happy to concede here but the consistency would be nice even when not functionally important.

@caddoo
Copy link
Contributor Author

caddoo commented Sep 5, 2024

In general the changes look good, I've got a few suggestions for better consistency and perhaps less code:

* keep the order of the methods in the interface consistent in order of get/set for a property, then get/set for the other. Now it's get/set/set/get.

* consider using a trait as the implementation of the four methods is identical across 4 classes. If other db schemas need different implementation they can opt to not use the trait and implement the methods directly.

If someone else feels like we shouldn't use a trait here I'd be happy to concede here but the consistency would be nice even when not functionally important.

Thanks for taking a look, i've reordered the methods to make it a bit more consistent.

I've added a commit with traits, take a look and tell me if you are happy with that approach, traits of course have their problems.

Copy link
Contributor

@michalkleiner michalkleiner left a comment

Choose a reason for hiding this comment

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

This looks good, thanks! The static vs the dynamic set of calls is annoying, it could probably be done somehow via some magic, but that would be at the expense of legibility and long-term maintainability, so all good as it is.

@sgiehl sgiehl added Technical debt Issues the will help to reduce technical debt and removed Needs Review PRs that need a code review labels Sep 6, 2024
@sgiehl sgiehl added this to the 5.2.0 milestone Sep 6, 2024
@sgiehl sgiehl merged commit 750fdce into 5.x-dev Sep 6, 2024
24 of 25 checks passed
@sgiehl sgiehl deleted the better-transaction-level-interface branch September 6, 2024 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org. Technical debt Issues the will help to reduce technical debt
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants