Commit ad4b595
refactor: optimize credit-service imports with lazy loading (calcom#25091)
* refactor: optimize credit-service imports with lazy loading
- Remove top-level imports of heavy modules (reminderScheduler, email services, i18n, billing services)
- Implement dynamic imports for modules only when needed:
- reminderScheduler: loaded only when SMS credit limit reached
- email services: loaded only when sending credit notifications
- getTranslation: loaded only when handling low credit balance
- InternalTeamBilling: loaded only in getMonthlyCredits method
- billing singleton: loaded only when calculating warning limits
- Break circular dependency: credit-service → reminderScheduler → ... → credit-service
- Update tests to mock StripeBillingService for dynamic imports
- All 30 tests passing, no type errors, lint clean
This reduces baseline import cost by deferring:
- Stripe SDK initialization (loaded twice before)
- 557KB+ i18n English translation file
- Email template classes
- Workflow reminder scheduler
Verified with madge: circular dependency successfully resolved
Co-Authored-By: morgan@cal.com <morgan@cal.com>
* fix: add null checks for billing.getPrice() return value
Co-Authored-By: morgan@cal.com <morgan@cal.com>
---------
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>1 parent a7cb717 commit ad4b595
2 files changed
Lines changed: 34 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
104 | 118 | | |
105 | 119 | | |
106 | 120 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | 4 | | |
11 | | - | |
12 | 5 | | |
13 | 6 | | |
14 | 7 | | |
15 | 8 | | |
16 | | - | |
17 | 9 | | |
18 | 10 | | |
19 | 11 | | |
| |||
474 | 466 | | |
475 | 467 | | |
476 | 468 | | |
477 | | - | |
478 | | - | |
479 | | - | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
480 | 472 | | |
481 | 473 | | |
482 | 474 | | |
| |||
495 | 487 | | |
496 | 488 | | |
497 | 489 | | |
| 490 | + | |
| 491 | + | |
498 | 492 | | |
499 | 493 | | |
500 | 494 | | |
| |||
591 | 585 | | |
592 | 586 | | |
593 | 587 | | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
594 | 592 | | |
595 | 593 | | |
596 | 594 | | |
| |||
602 | 600 | | |
603 | 601 | | |
604 | 602 | | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
605 | 606 | | |
606 | 607 | | |
607 | 608 | | |
| |||
613 | 614 | | |
614 | 615 | | |
615 | 616 | | |
| 617 | + | |
616 | 618 | | |
617 | 619 | | |
618 | 620 | | |
| |||
653 | 655 | | |
654 | 656 | | |
655 | 657 | | |
| 658 | + | |
656 | 659 | | |
657 | 660 | | |
658 | 661 | | |
| |||
668 | 671 | | |
669 | 672 | | |
670 | 673 | | |
671 | | - | |
| 674 | + | |
672 | 675 | | |
673 | 676 | | |
674 | 677 | | |
675 | 678 | | |
676 | 679 | | |
677 | 680 | | |
678 | 681 | | |
679 | | - | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
680 | 687 | | |
681 | 688 | | |
682 | 689 | | |
| |||
0 commit comments