Skip to content

Micro optimize setCustomAttribute call.#39

Merged
dvicklund merged 2 commits intomasterfrom
bugfix/set-custom-attribute
Dec 6, 2023
Merged

Micro optimize setCustomAttribute call.#39
dvicklund merged 2 commits intomasterfrom
bugfix/set-custom-attribute

Conversation

@tr3mulant
Copy link
Copy Markdown
Collaborator

@tr3mulant tr3mulant commented Dec 6, 2023

Micro optimization for CustomAttributeTrait.

The setCustomAttribute method had two fetches for the database for getting the custom attribute when the $attr wasn't a model and the attribute existed.

Now, the method just tries to resolve the attribute object by called resolveCustomAttributeObject in 3 ways.

  1. Early return if we already have a CustomAttribute
  2. Attempt to find it via the relationship in the method getCustomAttribute (which just actually checks if there is a CustomAttributeValue for the item tied to the CustomAttribute in question)
  3. Last resort will just fetch the CustomAttribute from the actual table

Copy link
Copy Markdown
Owner

@dvicklund dvicklund left a comment

Choose a reason for hiding this comment

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

Seems like a reasonable change - the hasCustomAttribute function is nonsense anyway - no need to get a model to see if it exists, then subsequently getCustomAttribute to return the actual model to the caller. Much better to minimize redundant calls. Merging

@dvicklund dvicklund merged commit e960145 into master Dec 6, 2023
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.

2 participants