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

✨ Adds option to ignore revision records with same old and new values ​​in Revisionable Trait #187

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

phpiando
Copy link

@phpiando phpiando commented Sep 1, 2024

Addition of a new revisionIgnoreSameValue property:

This property is a boolean flag that allows you to enable or disable the functionality of ignoring revisions where the old value is equal to the new one. By default, this functionality is disabled (false).

Implementation of the ignoreRevisionSameValue($oldValue, $newValue) method:

This method checks whether the revisionIgnoreSameValue property is enabled and, if so, returns true when the old value is equal to the new value, thus skipping the creation of the revision record.

Adjustment to revision creation logic in the revisionableAfterUpdate() method:

Added a check to call the ignoreRevisionSameValue method before adding a revision record.

Justification for Changes:

  • Optimization of Revision Records: By avoiding the creation of unnecessary revisions when values ​​do not change, the storage of revisions becomes more efficient and less polluted.
  • Flexibility: The new revisionIgnoreSameValue property allows developers to optionally control this functionality, which can be enabled or disabled according to the needs of the project.

Additional Notes:

Testing has been performed to ensure that the default behavior of the Revisionable trait has not changed and that revisions are still recorded correctly when this new functionality is disabled.
It is recommended that you review the documentation for additional information about this new option.

Checklist:

  • Code follows the project's style standards.
  • Tests have been added or updated to cover the new functionality.
  • Documentation has been updated as needed.

Added new method and property to ignore same values in revision
@bennothommo
Copy link
Member

Hi @phpiando - thanks for submitting this PR.

My understanding is that this trait already checks if revisionable fields have been changed or not from this line:

$dirty = $this->getDirty();
. The getDirty() method should only return fields that have been changed, so your additional check would be redundant at that point.

Do you have an example of the Revisionable trait saving unchanged data in a new revision?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants