-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[Maintenance] Fix VersionsCleanupStackTraceDbTask (performance + logic) #11855
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
[Maintenance] Fix VersionsCleanupStackTraceDbTask (performance + logic) #11855
Conversation
@BlackbitNeueMedien Thanks a lot for your PR, however I think we could even further optimize the process:
WDYT? 😊 |
@brusch I adjusted it to use a do-while-loop. I did not add |
This continues to kill the database in our client's case:
The only alternative I see is a "computed column" as described in https://stackoverflow.com/a/12048065 |
I added an index to |
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.
Regarding setting the stack trace to null:
What I meant is that we're currently saving the whole version again by calling $version->getDao()->save();
. I'd rather implement a dedicated method, like $version->getDao()->clearStrackTrace();
that just uses:
$this->db->update('versions', ['stackTrace' => null], ['id' => $this->model->getId()]);
to set the stack trace to null
, which will be much more efficient, right?
@brusch Ok, I thought it had a reason that we save the version again. But if not, then we can completely simplify this task to Db::get()->executeUpdate('UPDATE versions SET stackTrace = NULL WHERE date < ? AND stackTrace IS NOT NULL', [time() - 86400 * 7]); WDYT? |
@BlackbitNeueMedien LGTM, can you just quickly fix the issue reported by PhpStan? Thanks again! |
Done. This PR is really a simplification ;-) |
Love it 💕 Thanks a lot! |
Current logic in
pimcore/lib/Maintenance/Tasks/VersionsCleanupStackTraceDbTask.php
Line 55 in 9ecae6b
LIMIT 0,500
stackTrace
for those 500 found versions gets set toNULL
LIMIT 500,500
in the next iteration, you will not find anything because after 3. there are only 100 versions left which match the conditionstackTrace IS NOT NULL
But the even more severe problem is performance: We just had these processes:

(Don't know if maintenance job locking did not work but was running with Pimcore 10.0, so this does not matter for now)
The problem is the
filesort
which has to be done because the database uses the index onautoSave
(this condition gets added inpimcore/models/Version/Listing/Dao.php
Lines 30 to 36 in 9ecae6b
We could create an optimized index but ordering in this case is not necessary anyway as we want to change stack trace for all found versions.