Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: refresh the cache for subscription (#3828)

ecmadaoad45ac31bf65
diff --git a/enterprise/api/license.go b/enterprise/api/license.go
index 9db0917f71..63ae04c911 100644
--- a/enterprise/api/license.go
+++ b/enterprise/api/license.go
@@ -68,4 +68,6 @@ type LicenseService interface {
GetEffectivePlan() api.PlanType
// GetPlanLimitValue gets the limit value for the plan.
GetPlanLimitValue(name api.PlanLimit) int64
+ // RefreshCache will invalidate and refresh the subscription cache.
+ RefreshCache(ctx context.Context)
}
diff --git a/enterprise/service/license.go b/enterprise/service/license.go
index 5752abba6d..c77e78e752 100644
--- a/enterprise/service/license.go
+++ b/enterprise/service/license.go
@@ -64,9 +64,7 @@ func (s *LicenseService) StoreLicense(ctx context.Context, patch *enterpriseAPI.
return err
}
- // Invalidate and refresh the subscription cache.
- s.cachedSubscription = nil
- s.LoadSubscription(ctx)
+ s.RefreshCache(ctx)
return nil
}
@@ -126,6 +124,12 @@ func (s *LicenseService) GetPlanLimitValue(name api.PlanLimit) int64 {
return v[s.GetEffectivePlan()]
}
+// RefreshCache will invalidate and refresh the subscription cache.
+func (s *LicenseService) RefreshCache(ctx context.Context) {
+ s.cachedSubscription = nil
+ s.LoadSubscription(ctx)
+}
+
// loadLicense will load license and validate it.
func (s *LicenseService) loadLicense(ctx context.Context) (*enterpriseAPI.License, error) {
// Find enterprise license.
diff --git a/server/subscription.go b/server/subscription.go
index ed28f84552..e297d44a0a 100644
--- a/server/subscription.go
+++ b/server/subscription.go
@@ -116,10 +116,9 @@ func (s *Server) registerSubscriptionRoutes(g *echo.Group) {
// Case 1: Users just have the SettingEnterpriseTrial, don't upload their license in SettingEnterpriseLicense.
// Case 2: Users have the SettingEnterpriseLicense with team plan and trialing status.
// In both cases, we can override the SettingEnterpriseLicense with an empty value to get the valid free trial.
- if _, err := s.store.PatchSetting(ctx, &api.SettingPatch{
+ if err := s.licenseService.StoreLicense(ctx, &enterpriseAPI.SubscriptionPatch{
UpdaterID: principalID,
- Name: api.SettingEnterpriseLicense,
- Value: "",
+ License: "",
}); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to remove license").SetInternal(err)
}
@@ -135,6 +134,7 @@ func (s *Server) registerSubscriptionRoutes(g *echo.Group) {
}
}
+ s.licenseService.RefreshCache(ctx)
subscription = s.licenseService.LoadSubscription(ctx)
currentPlan := subscription.Plan
if s.MetricReporter != nil {