Replace polling with database watchers for improved efficiency #160
+358
−96
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
This PR replaces inefficient polling mechanisms with database watchers throughout the codebase, significantly improving responsiveness and reducing resource usage. The changes provide real-time updates for TUI, task scheduling, and Claude task completion monitoring while maintaining necessary polling for external APIs and time-based operations.
Changes
Database Watcher Implementation
TUI Integration: Added tracking database watcher to
cmd/tui_plan.gofor real-time work/task updatesScheduler Optimization: Replaced polling in
cmd/scheduler_handler.gowith database watcherClaude Task Monitoring: Replaced 2-second polling in
internal/claude/inline.goPerformance Optimizations
Documentation
docs/polling-patterns.mdIssues Resolved
Performance Impact
Testing Performed
Breaking Changes
None. All changes are backward compatible and include fallback mechanisms.
Review Notes
Files Modified
cmd/orchestrate.go- Reduced polling intervalscmd/scheduler_handler.go- Added database watcher integrationcmd/tui_plan.go- Integrated tracking watchercmd/tui_plan_data.go- Removed periodic refresh logicinternal/claude/inline.go- Replaced polling with watcherdocs/polling-patterns.md- New documentation fileCo-Authored-By: Claude Opus 4.1 noreply@anthropic.com