Skip to content

perf(cleanup): Optimize cleanup job - #9166

Open
Koc wants to merge 3 commits into
mainfrom
feature/optimize-cleanup-job
Open

perf(cleanup): Optimize cleanup job#9166
Koc wants to merge 3 commits into
mainfrom
feature/optimize-cleanup-job

Conversation

@Koc

@Koc Koc commented Sep 3, 2026

Copy link
Copy Markdown

馃摑 Summary

This is continuation of the #8421.

Problem:

The text app cleanup background job took roughly 800 seconds per run. The loop over documents with no active session unconditionally called cleanupAttachments, even for documents that had unsaved changes and could not be reset. The same ~8,000 documents kept re-entering the cleanup loop every cron run, and cleanupAttachments is expensive because it resolves the file, reads Markdown content, scans the database, and iterates the attachment directory.

Solution:

  • Attempt to resetDocument before running cleanupAttachments.
  • Catch DocumentHasUnsavedChangesException:
    • If unsaved changes are recent (last step within 30 days), skip the document. Attachment references may only exist in the unsaved state, so cleaning them now would be incorrect.
    • If unsaved changes are older than 30 days, force-reset the document, log a warning, and then clean up attachments.
  • Added a helper to fetch the latest step timestamp for a document.

Impact:

  • Cleanup cron runtime dropped from ~800 seconds to ~20 seconds.
  • Abandoned unsaved changes older than 30 days are now cleaned up instead of accumulating forever.

馃弫 Checklist

  • Code is properly formatted (npm run lint / npm run stylelint / composer run cs:check)
  • Sign-off message is added to all commits
  • Tests (unit, integration and/or end-to-end) passing and the changes are covered with tests
  • Documentation (README or documentation) has been updated or is not required

馃 AI (if applicable)

  • The content of this PR was partly or fully generated using AI tools
  • The AI-generated content was reviewed, comprehended and tested by a human

Signed-off-by: Kostiantyn Miakshyn <molodchick@gmail.com>
@Koc
Koc force-pushed the feature/optimize-cleanup-job branch from 9e25cf3 to 4aa0029 Compare September 13, 2026 14:18
Koc added 2 commits September 13, 2026 16:31
Signed-off-by: Kostiantyn Miakshyn <molodchick@gmail.com>
Signed-off-by: Kostiantyn Miakshyn <molodchick@gmail.com>
@Koc
Koc force-pushed the feature/optimize-cleanup-job branch from 41cd3d3 to 723e88c Compare September 13, 2026 14:38
@Koc
Koc marked this pull request as ready for review September 13, 2026 15:52
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.

1 participant