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

Add Elements repository #2039

Merged
merged 6 commits into from
Mar 5, 2021
Merged

Conversation

tvdeyen
Copy link
Member

@tvdeyen tvdeyen commented Mar 1, 2021

What is this pull request for?

Adds a repository class that mimics the ActiveRecord interface of elements, but uses the eager loaded elements and POR methods to filter the collection.

With that we filter the elements in the elements finder (used in the render_elements helper) on a eager loaded elements collection.

Checklist

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • I have added tests to cover this change

Copy link
Contributor

@mamhoff mamhoff left a comment

Choose a reason for hiding this comment

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

Hm, tests are still failing, please disregard my approval...

@tvdeyen
Copy link
Member Author

tvdeyen commented Mar 1, 2021

Hm, tests are still failing, please disregard my approval...

@mamhoff and it's a draft PR ;) But I still would like to hear your feedback

@tvdeyen tvdeyen force-pushed the element-repository branch 2 times, most recently from f85b455 to 7819787 Compare March 2, 2021 13:54
@tvdeyen tvdeyen force-pushed the element-repository branch 2 times, most recently from a136a91 to 75da500 Compare March 2, 2021 18:04
@tvdeyen tvdeyen marked this pull request as ready for review March 2, 2021 20:38
@tvdeyen tvdeyen requested a review from mamhoff March 2, 2021 20:39
This mimics the ActiveRecord interface of elements, but
uses the eager loaded elements and POR methods to filter
the collection
It is very common to chain ActiveRecord scopes to filter elements.

This makes it possible with the ElementRepository by returning a new instance
of the class for each of the scope methods.
These scopes are used on the ElementsFinder and needs to
be supported.
This is way fast than using create and since we only use
array methods in the repository
class its totally safe to use it.
The elements repository uses array methods to filter, order and limit
elements on a eager loaded ActiveRecord relation.

This should help to prevent N+1 queries in the future.
@hound hound bot deleted a comment from tvdeyen Mar 3, 2021
Copy link
Contributor

@mamhoff mamhoff left a comment

Choose a reason for hiding this comment

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

Let's go with this as well!

Rufo uses the same default as Rubocop here.

By removing the override we use the dewfault of Rubocop.
@tvdeyen tvdeyen merged commit 16e7278 into AlchemyCMS:main Mar 5, 2021
@tvdeyen tvdeyen deleted the element-repository branch March 5, 2021 12:48
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