-
-
Notifications
You must be signed in to change notification settings - Fork 315
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
Faster element duplication #2066
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The Element Repository behaves a lot like an ActiveRecord::Relation, but does everything in-memory rather than executing SQL. This will allow us to increase performance when reading elements from a page version.
When copying, we copy a content to another element. We need to skip the element ID in these cases.
This will help us render and copy nested elements!
When creating an element, we do not need to touch it for every time it creates a content.
This change aligns the Hash we're merging into with the Hash we're merging from.
This adds a service class that duplicates an element quickly. It can accept an optional repository so that nested elements do not generate new database calls.
It's faster, and we get to remove some code from the Element class.
This should speed up page publishing considerably. Specs are sufficient.
`tag_list` generates a query for each element, even if they're already loaded.
This speeds up page publishing by a fair amount.
mamhoff
force-pushed
the
faster-element-duplication
branch
3 times, most recently
from
April 12, 2021 15:17
c76eafe
to
a3386fc
Compare
tvdeyen
reviewed
Apr 12, 2021
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice. I think we can have accurate positions and the performance improvement.
This saves a query per element!
These specs would previously fail as their element's updated at would not, actually, be `3.hours.ago`, but `Time.current - $TESTRUNTIME`. This is more explicit with setting the column, and fixes the specs.
mamhoff
force-pushed
the
faster-element-duplication
branch
from
April 13, 2021 07:20
a3386fc
to
e285498
Compare
tvdeyen
reviewed
Apr 13, 2021
tvdeyen
reviewed
Apr 13, 2021
This makes sure the element indexes start with 1, as `acts_as_list` expects. It also wraps the creation of nested elements in the `DuplicateElement` class in an `Element.acts_as_list_no_update` block. The code in here is safe, and when called from e.g. Alchemy::Element#copy, it makes it faster, too.
tvdeyen
approved these changes
Apr 13, 2021
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What is this pull request for?
This speeds up element duplication by picking all child elements from the source element's page version's element repository, the creating the new elements, without touching related database records or updating element positions.
The speedup here is considerable: In a tiny benchmark, we managed to reduce publishing time by more than half:
Main branch:
This branch:
The benchmark is the following file, feel free to add it to your project and try yourself:
This is co-authored by @tvdeyen - I just cleaned up the commit history and added some specs.
Checklist