feat: Refresh billable user counts on SM license creation

What does this MR do and why?

When a new self-managed license is applied, the billable user counts (Users in subscription, Billable users, Maximum users, Users over subscription) are not updated until the next scheduled background job runs, which can be up to 24 hours later. This means admins see stale user counts after applying a new license.

This MR adds an after_create callback to the License model that enqueues Analytics::UsageTrends::CounterJobWorker immediately after a license is created, but only when the license has already started (i.e., starts_at <= Date.current). Future-dated licenses are skipped since the counts would not be relevant until the license becomes active.

References

Screenshots or screen recordings

Before After
Screenshot 2026-04-07 at 10.46.42.png Screenshot 2026-04-07 at 10.42.28.png

How to set up and validate locally

  1. In a rails console, check the current billable user count:

    License.current.daily_billable_users_count
  2. Purchase a premium/ultimate subscription and apply the new activation code via the Admin UI admin/subscription.

  3. Observe that Analytics::UsageTrends::CounterJobWorker is enqueued immediately.

  4. After the job completes, verify the user counts are updated in the Admin UI under Admin > Subscription.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Divya Mahadevan

Merge request reports

Loading
Loading