[HIGH] Refactor getNextPaydays to mathematical computation - eliminate day-by-day loop #37

Closed
opened 2026-06-09 00:03:13 +00:00 by Mark · 0 comments
Owner

Location: backend/src/services/PaydayService.ts:24-42

Problem: getNextPaydays uses a brute-force while loop iterating every calendar day until count paydays are found. For biweekly/monthly schedules, this iterates 30–350+ days per call.

Impact: O(days) per lookup. For monthly schedules near month boundaries, this is 10–1,000x slower than necessary.

Fix: Replace with arithmetic:

  • Weekly: start + ceil((today - start) / 7) * 7
  • Biweekly: start + ceil((today - start) / 14) * 14
  • Monthly: new Date(today.getFullYear(), today.getMonth(), dayOfMonth)
  • Twice-monthly: pick next of [d1, d2] >= today

Effort: ~2 hours

**Location:** `backend/src/services/PaydayService.ts:24-42` **Problem:** `getNextPaydays` uses a brute-force `while` loop iterating every calendar day until `count` paydays are found. For biweekly/monthly schedules, this iterates 30–350+ days per call. **Impact:** O(days) per lookup. For monthly schedules near month boundaries, this is 10–1,000x slower than necessary. **Fix:** Replace with arithmetic: - Weekly: `start + ceil((today - start) / 7) * 7` - Biweekly: `start + ceil((today - start) / 14) * 14` - Monthly: `new Date(today.getFullYear(), today.getMonth(), dayOfMonth)` - Twice-monthly: pick next of `[d1, d2] >= today` **Effort:** ~2 hours
Mark 2026-06-09 00:03:13 +00:00
  • closed this issue
  • added the
    bug
    label
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Mark/subvault#37
No description provided.