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 BaseActiveRecord::getDirtyAttributes() #283

Merged
merged 8 commits into from
Jan 14, 2024

Conversation

Tigrov
Copy link
Member

@Tigrov Tigrov commented Dec 27, 2023

  • Improve performance
  • Allow to use class properties (mixed with $attributes if no class properties) for table row values.
Q A
Is bugfix?
New feature?
Breaks BC?
Fixed issues -

Copy link

codecov bot commented Dec 27, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (c5f92e5) 88.02% compared to head (b894025) 87.79%.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #283      +/-   ##
============================================
- Coverage     88.02%   87.79%   -0.23%     
+ Complexity      587      580       -7     
============================================
  Files             7        7              
  Lines          1319     1311       -8     
============================================
- Hits           1161     1151      -10     
- Misses          158      160       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

what-the-diff bot commented Dec 27, 2023

PR Summary

  • Modification to BaseActiveRecord.php

    • Incorporated two additional functions into the file (array_diff_key and array_intersect_key).
    • Updated getDirtyAttributes method to better manage when $names is not defined or null.
    • Updated variables for improved clarity and accuracy within the code.
    • Streamlined the execution of the getDirtyAttributes method.
  • Updation to ActiveRecordTest.php

    • For ensuring solid, reliable software, two new testing methods have been added (testGetDirtyAttributesOnNewRecord and testGetDirtyAttributesAfterFind).
    • Enhanced the test coverage of the getDirtyAttributes method to cover multiple use case scenarios.

@Tigrov Tigrov marked this pull request as draft December 29, 2023 06:40
@Tigrov Tigrov marked this pull request as ready for review December 29, 2023 09:20
@Tigrov Tigrov added the status:code review The pull request needs review. label Dec 29, 2023
}

return $values;
return array_intersect_key($attributes, array_flip($names));
Copy link
Member

Choose a reason for hiding this comment

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

Could you bench it?

Copy link
Member

Choose a reason for hiding this comment

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

What about oldAttributes?

Copy link
Member Author

Choose a reason for hiding this comment

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

Could you bench it?

Before:
benchGetAttributes......................R1 I1 - Mo20.920μs (±1.00%)

After:
benchGetAttributes......................R2 I2 - Mo17.238μs (±1.78%)

Copy link
Member Author

Choose a reason for hiding this comment

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

What about oldAttributes?

getOldAttributes() is a different method, without changes.

# Conflicts:
#	tests/ActiveRecordTest.php
@Tigrov Tigrov merged commit fb7f4a8 into master Jan 14, 2024
55 of 57 checks passed
@Tigrov Tigrov deleted the refactor-getDirtyAttributes branch January 14, 2024 02:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:code review The pull request needs review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants