mirror of
https://github.com/xtr-dev/payload-mailing.git
synced 2025-12-11 08:43:24 +00:00
🎯 Simplifications: - Removed complex beforeChange hook - all logic now in afterChange - Single clear decision point with 'shouldSkip' variable - Document ID always available in afterChange - Clearer comments explaining the logic flow 🛡️ Concurrent Update Protection: - ensureEmailJob now handles race conditions properly - Double-checks for jobs after creation failure - Idempotent function safe for concurrent calls - Better error handling and recovery 📊 Benefits: - Much simpler hook logic (from ~70 lines to ~40 lines) - Single source of truth (afterChange only) - No complex hook interactions - Clear skip conditions - Concurrent update safety - Better code readability 🔍 How it works: 1. Check skip conditions (not pending, has jobs, etc.) 2. Call ensureEmailJob (handles all complexity) 3. Update relationship if needed 4. Log errors but don't fail operations