Make file analysis actually async and surface status in the UI#23
Merged
Conversation
`ProjectReport.save()` was invoking `NewProjectReportThread(self).run()`, which executes the thread body in the current thread instead of spawning a new one. The analyze view blocked for the full difflib pass before returning, making the frontend polling (project.js:checkReport) wait 5s for nothing on the first check. Switch to `.start()` so analysis runs in a real OS thread and the existing polling/status-endpoint pair actually does work across the 1 → 2 → 3 transition. Wrap the thread body in try/finally to release the implicit Django DB connection the worker thread opens, otherwise each Analyze click leaks one connection. Update the model test that was asserting the bug (`.run()`) to assert `.start()`. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Mirrors the Files and Reference table layout (Created / Status / open action) and surfaces report.get_status_display so async processing states (Ready for Processing, Processing, Complete) are visible.
Inject a "Ready for Processing" row into the Reports table the moment Analyze fires, then update its status badge as polling sees the report move 1 → 2 → 3. Removes the manual-refresh toast entirely and the status=3 filter on the project view, so in-progress reports also render on initial page load. On load, any non-Complete row resumes polling so a mid-flight refresh keeps tracking the same report.
The report page was using the singular `breadcrumb` class on a bare `<ul>`, which is not daisyUI's component and rendered as a plain bulleted list with no separators. Switch to the wrapping `<div class="text-sm breadcrumbs"><ul>...</ul></div>` pattern and link styling used by every other breadcrumbed template (project, tm, newproject, newtm, tm-import).
This file contains hidden or 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
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.
Summary
NewProjectReportThread(self).run()was running the analysis synchronously in the request worker (.run()executes in the current thread;.start()is what spawns a new one). Switched to.start()and wrapped the thread body intry/finally: connection.close()so the per-thread DB connection is released.1 → 2 → 3. The "Your report is ready. Please refresh this page" toast is gone. On page load, any row that isn't Complete resumes polling, so a mid-flight refresh keeps tracking the same report.breadcrumb(singular) on a bare<ul>, which rendered as a plain bulleted list with no separators. Switched to the wrapping<div class="text-sm breadcrumbs"><ul>…</ul></div>pattern used by every other breadcrumbed template.Test plan
python manage.py test— 256 tests pass (existing test that asserted the bug,test_save_with_status_1_triggers_thread, was updated to mock.start()).ruff check .andruff format --check .— clean.Projects > {project} > Report — {date}) renders with>separators and the same styling as the project page.🤖 Generated with Claude Code