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

[4.x]: Revisions for Matrix fields can't be pruned, causing GC issues #16373

Open
janhenckens opened this issue Jan 2, 2025 · 8 comments
Open

Comments

@janhenckens
Copy link
Contributor

What happened?

Description

I'm troubleshooting a database that has grown is size quicker then we had expected and I fell down a bit of a rabbit hole...

We have couple of sections that received content from an API every night, when we overwrite everything that was already present with new data.

This includes a couple of matrix fields, which get deleted very night (since launching we've convinced them to only send updates, which reduces the update frequency) and those elements aren't cleared out when garbage collection runs.

Looking at the code, I found that block-type elements don't get cleaned up if they have revisions.

Pruning all revisions (php craft utils/prune-revisions/index and setting them to 0) doesn't seem to clear out revisions for matrix blocks as after running the above command still leaves 2 revisions for a matrix block.

So I'm not sure how to proceed in getting this cleaned up, and I'm not sure if this is a bug or not...

Thanks

Craft CMS version

4.12.6.1

PHP version

8.2

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

@i-just
Copy link
Contributor

i-just commented Jan 3, 2025

Hi, thanks for getting in touch!

block-type elements don't get cleaned up if they have revisions

That’s expected behaviour; it works this way so that if you revert to a revision that had a matrix block, that block is brought back, too.

Pruning all revisions (php craft utils/prune-revisions/index and setting them to 0) doesn't seem to clear out revisions for matrix blocks as after running the above command still leaves 2 revisions for a matrix block.

When you run the utils/prune-revisions command (in v4), the owner element revisions are removed.

If you run the gc/run command after pruning revisions, those matrix blocks should be removed.

@janhenckens
Copy link
Contributor Author

Thanks for confirming @i-just!

If you run the gc/run command after pruning revisions, those matrix blocks should be removed.

Only that's not happening... I prune all revisions, run gc/run and the deleted matrix blocks are still present in the database.

This was set up by someone else as a supportable field with different matrix fields inside it - may that structure is what is causing the issue?

@i-just
Copy link
Contributor

i-just commented Jan 3, 2025

Huh, any chance you could share your composer.json, composer.lock and database export? If so, please send to [email protected] and point out which entry you’ve been testing with.

@janhenckens
Copy link
Contributor Author

Sure, they're on their way :)

@brandonkelly
Copy link
Member

@janhenckens Do you have recursively-nested Matrix fields? If so, it might require running gc multiple times.

@brandonkelly
Copy link
Member

Resolved in support. Ended up being due to missing foreign keys in the database.

@janhenckens
Copy link
Contributor Author

Foreign keys were missing because of the export I made, but they are present in the database - still looking for solution for this...

@brandonkelly brandonkelly reopened this Jan 6, 2025
@i-just
Copy link
Contributor

i-just commented Jan 7, 2025

Thanks for sending over a new db backup! I tracked it down to the fact that the Matrix blocks you mentioned are nested inside a Super Table field and the Super Table blocks are not cleared out via utils/prune-revisions or gc/run. I replied with more details via support. We’ll also be discussing this further internally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants