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

Fast element deletion #2063

Merged
merged 2 commits into from
Apr 9, 2021
Merged

Conversation

mamhoff
Copy link
Contributor

@mamhoff mamhoff commented Apr 9, 2021

What is this pull request for?

This speeds up a part of the page publishing process: That of deleting the existing elements on an already published page. Prior to this PR, element deletion would rely on the element's before_destroy hooks, needing to make an SQL query for every element in the page tree. This speeds this up considerably by deleting all elements, contents and essences on the page version in 2 + (number of essence types used) queries.

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

mamhoff added 2 commits April 9, 2021 14:15
Deleting a collection of elements is rather slow at the moment. As
elements as well as contents have a `dependent: :destroy` on them, every
dependent record needs to be loaded and destroyed individually.

This class uses the knowledge we have of elements, contents and essences
in order to be able to destroy a collection of elements in a maximum of
less than 20 database calls (if the collection of elements uses a lot of
different essences, more calls happen, but there's only a limited amount
of essence classes).

There's one additional call to the database in here as a safeguard so we
do not produce orphaned elements. It's fast, and gives a sense of
security.
A page version's elements collection is comprised of all elements linked
to a page version, so we can use the fast element deletion class
introduced in the previous commit.
Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

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

This is great. Thanks

@mamhoff mamhoff merged commit 8b915e6 into AlchemyCMS:main Apr 9, 2021
robinboening pushed a commit to robinboening/alchemy_cms that referenced this pull request Jul 2, 2021
* Add a fast element deletion service class

Deleting a collection of elements is rather slow at the moment. As
elements as well as contents have a `dependent: :destroy` on them, every
dependent record needs to be loaded and destroyed individually.

This class uses the knowledge we have of elements, contents and essences
in order to be able to destroy a collection of elements in a maximum of
less than 20 database calls (if the collection of elements uses a lot of
different essences, more calls happen, but there's only a limited amount
of essence classes).

There's one additional call to the database in here as a safeguard so we
do not produce orphaned elements. It's fast, and gives a sense of
security.

* Use fast element deletion class in page publisher

A page version's elements collection is comprised of all elements linked
to a page version, so we can use the fast element deletion class
introduced in the previous commit.
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