Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat: cache subscription (#555)
ecmadao87a0b7a086d1
diff --git a/bin/server/cmd/root.go b/bin/server/cmd/root.goindex 5628c4bbba..d296d0b9f5 100644--- a/bin/server/cmd/root.go+++ b/bin/server/cmd/root.go@@ -345,6 +345,7 @@ func (m *Main) Run(ctx context.Context) error {return err}s.LicenseService = licenseService+ s.InitSubscription()m.server = sdiff --git a/server/server.go b/server/server.goindex 76b7dd5041..58182ea9cc 100644--- a/server/server.go+++ b/server/server.go@@ -83,6 +83,7 @@ type Server struct {readonly booldemo booldataDir string+ subscription *enterprise.Subscription}//go:embed acl_casbin_model.conf@@ -252,6 +253,11 @@ func NewServer(logger *zap.Logger, version string, host string, port int, frontereturn s}+// InitSubscription will initial the subscription cache in memory+func (server *Server) InitSubscription() {+ server.subscription = server.loadSubscription()+}+// Run will run the server.func (server *Server) Run() error {if !server.readonly {diff --git a/server/subscription.go b/server/subscription.goindex 74b0a40610..24b7eb339c 100644--- a/server/subscription.go+++ b/server/subscription.go@@ -14,10 +14,8 @@ import (func (s *Server) registerSubscriptionRoutes(g *echo.Group) {g.GET("/subscription", func(c echo.Context) error {- subscription := s.loadSubscription()-c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)- if err := jsonapi.MarshalPayload(c.Response().Writer, subscription); err != nil {+ if err := jsonapi.MarshalPayload(c.Response().Writer, s.subscription); err != nil {return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal subscription response").SetInternal(err)}return nil@@ -33,10 +31,10 @@ func (s *Server) registerSubscriptionRoutes(g *echo.Group) {return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create license").SetInternal(err)}- subscription := s.loadSubscription()+ s.subscription = s.loadSubscription()c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)- if err := jsonapi.MarshalPayload(c.Response().Writer, subscription); err != nil {+ if err := jsonapi.MarshalPayload(c.Response().Writer, s.subscription); err != nil {return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal subscription response").SetInternal(err)}return nil@@ -87,6 +85,5 @@ func (server *Server) loadLicense() (*enterpriseAPI.License, error) {}func (s *Server) feature(feature api.FeatureType) bool {- subscription := s.loadSubscription()- return api.FeatureMatrix[feature][subscription.Plan]+ return api.FeatureMatrix[feature][s.subscription.Plan]}