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

Implementation/47064 support custom field in the attributesbytimestamp #13158

Conversation

dombesz
Copy link
Contributor

@dombesz dombesz commented Jul 18, 2023

@dombesz dombesz force-pushed the implementation/47064-support-custom_field_-in-the-attributesbytimestamp branch 8 times, most recently from c1e1be4 to 0e1ec97 Compare July 21, 2023 06:20
@dombesz dombesz marked this pull request as ready for review July 21, 2023 11:26
@dombesz dombesz force-pushed the implementation/47064-support-custom_field_-in-the-attributesbytimestamp branch from c77b6b6 to a371ddf Compare July 21, 2023 11:30
Copy link
Contributor

@ulferts ulferts left a comment

Choose a reason for hiding this comment

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

Hey Attila, I like the change. The number of places touched is really kept in check nicely.

I have two tiny remarks in the code and one issue that can also be addressed in a subsequent PR. That is actually what I would suggest, to fix the two small issues and have the bigger issue addressed separately.

The bigger issue is an N+1 query when the diff for the representer is created:

image

We also have https://community.openproject.org/wp/48572 where we might place the fix in. It is not strictly the same but related.

end
end

def no_nil_to_empty_strings?(normalized_old_data, attribute, new_value)
old_value = normalized_old_data[attribute]
new_value != old_value && (new_value.present? || old_value.present?)
new_value != old_value
Copy link
Contributor

@ulferts ulferts Jul 24, 2023

Choose a reason for hiding this comment

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

I thinks this method no longer serves it's purpose of checking whether value might have changed from e.g. nil to '' as the method name suggests.

new_value = nil
old_value = ''

new_value != old_value && (new_value.present? || old_value.present?)
=> false

new_value != old_value
=> true

To have the implementation be more explicit, one could change it into

 ([new_value, old_value] - ['', nil]).any?

Update note In an earlier version of this old_value = nil was specified which was incorrect.

Copy link
Contributor

Choose a reason for hiding this comment

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

It is unsettling that no spec pics up on this. So I don't know how relevant my complaint is.

Copy link
Contributor Author

@dombesz dombesz Jul 25, 2023

Choose a reason for hiding this comment

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

I made the changes here 953bdf0. The expectations now fail in case any of the nil -> '' attribute transitions are included.
Some minor adjustment was required on the conditions, because [false].any? returns false and it breaks the expectation when a transition happens from nil -> false. I used ([new_value, old_value] - ['', nil]).present? instead.

Journal
.where(id: journal_ids)
.includes({ customizable_journals: :custom_field })
.index_by(&:id)
Copy link
Contributor

Choose a reason for hiding this comment

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

Tiny thing: The Journal needn't be involved in the loading. The same result can be achieved by

Journal::CustomizableJournal
  .where(journal_id: journal_ids)
  .includes(:custom_field)
  .index_by(&:journal_id)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 57c3bf0

@dombesz
Copy link
Contributor Author

dombesz commented Jul 25, 2023

Thanks for the thorough review @ulferts. I addressed your remarks except the N+1 issue, that will be addressed separately. From my side this PR is good to go, once the CI is green.

@dombesz dombesz requested a review from ulferts July 25, 2023 10:03
Copy link
Contributor

@ulferts ulferts left a comment

Choose a reason for hiding this comment

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

👍 merge at will

@dombesz dombesz merged commit 13c865d into dev Jul 25, 2023
11 checks passed
@dombesz dombesz deleted the implementation/47064-support-custom_field_-in-the-attributesbytimestamp branch July 25, 2023 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants