feat: centralize app release configuration
This commit is contained in:
@@ -60,6 +60,7 @@ var (
|
||||
tenantByIDCache = newConfigCache[*types.Tenant]()
|
||||
registrationSMSCache = newConfigCache[bool]()
|
||||
thirdPartyConfigCache = newConfigCache[map[string]string]()
|
||||
appReleaseConfigCache = newConfigCache[*types.AppRelease]()
|
||||
thirdPartyConfigAllKeys = "*"
|
||||
)
|
||||
|
||||
@@ -71,6 +72,11 @@ func cloneTenant(t *types.Tenant) *types.Tenant {
|
||||
return &cp
|
||||
}
|
||||
|
||||
// InvalidateAppReleaseConfigCache clears global client release policies.
|
||||
func InvalidateAppReleaseConfigCache() {
|
||||
appReleaseConfigCache.clear()
|
||||
}
|
||||
|
||||
func cloneStringMap(src map[string]string) map[string]string {
|
||||
if src == nil {
|
||||
return nil
|
||||
|
||||
+18
-4
@@ -169,6 +169,7 @@ type AdminInternalConfigProvider interface {
|
||||
ListActiveTenants(limit int) ([]types.Tenant, error)
|
||||
RegistrationSMSEnabled() (bool, error)
|
||||
ThirdPartyConfig(group string, keys ...string) (map[string]string, error)
|
||||
LatestAppRelease(platform, channel string) (*types.AppRelease, error)
|
||||
}
|
||||
|
||||
var adminInternalConfigProvider AdminInternalConfigProvider
|
||||
@@ -2728,24 +2729,37 @@ type profileMapper struct{}
|
||||
var Profiles ProfilePersistenceInterface
|
||||
|
||||
type AppReleasePersistenceInterface interface {
|
||||
Latest(tenantID types.TenantID, platform, channel string) (*types.AppRelease, error)
|
||||
Latest(platform, channel string) (*types.AppRelease, error)
|
||||
}
|
||||
|
||||
type appReleaseMapper struct{}
|
||||
|
||||
var AppReleases AppReleasePersistenceInterface
|
||||
|
||||
func (appReleaseMapper) Latest(tenantID types.TenantID, platform, channel string) (*types.AppRelease, error) {
|
||||
func (appReleaseMapper) Latest(platform, channel string) (*types.AppRelease, error) {
|
||||
platform = strings.ToLower(strings.TrimSpace(platform))
|
||||
channel = strings.ToLower(strings.TrimSpace(channel))
|
||||
if platform == "" || channel == "" {
|
||||
return nil, types.ErrMalformed
|
||||
}
|
||||
tenantAdp, err := tenantBusinessAdapter(tenantID)
|
||||
cacheKey := platform + ":" + channel
|
||||
if cached, ok := appReleaseConfigCache.get(cacheKey); ok {
|
||||
copy := *cached
|
||||
return ©, nil
|
||||
}
|
||||
if adminInternalConfigProvider == nil {
|
||||
return nil, types.ErrUnsupported
|
||||
}
|
||||
release, err := adminInternalConfigProvider.LatestAppRelease(platform, channel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return tenantAdp.TenantAppReleaseLatest(tenantID, platform, channel)
|
||||
if release == nil {
|
||||
return nil, types.ErrNotFound
|
||||
}
|
||||
copy := *release
|
||||
appReleaseConfigCache.set(cacheKey, ©)
|
||||
return release, nil
|
||||
}
|
||||
|
||||
type DevicePushTokenPersistenceInterface interface {
|
||||
|
||||
Reference in New Issue
Block a user