From fd17b22ffcc4e8cddeee8b02df46aa1f7fa4e68e Mon Sep 17 00:00:00 2001 From: Zeeshan Ashraf Date: Wed, 26 Jan 2022 17:34:14 -0800 Subject: [PATCH 1/2] Moved OptimizelyConfig Generation from SDK initialization to API Call --- .../config_manager/http_project_config_manager.rb | 14 +++++++++++--- .../static_project_config_manager.rb | 9 +++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/optimizely/config_manager/http_project_config_manager.rb b/lib/optimizely/config_manager/http_project_config_manager.rb index f6c02840..5b4f8727 100644 --- a/lib/optimizely/config_manager/http_project_config_manager.rb +++ b/lib/optimizely/config_manager/http_project_config_manager.rb @@ -33,7 +33,7 @@ module Optimizely class HTTPProjectConfigManager < ProjectConfigManager # Config manager that polls for the datafile and updated ProjectConfig based on an update interval. - attr_reader :stopped, :optimizely_config + attr_reader :stopped # Initialize config manager. One of sdk_key or url has to be set to be able to use. # @@ -80,8 +80,8 @@ def initialize( @last_modified = nil @skip_json_validation = skip_json_validation @notification_center = notification_center.is_a?(Optimizely::NotificationCenter) ? notification_center : NotificationCenter.new(@logger, @error_handler) + @optimizely_config = nil @config = datafile.nil? ? nil : DatafileProjectConfig.create(datafile, @logger, @error_handler, @skip_json_validation) - @optimizely_config = @config.nil? ? nil : OptimizelyConfig.new(@config).config @mutex = Mutex.new @resource = ConditionVariable.new @async_scheduler = AsyncScheduler.new(method(:fetch_datafile_config), @polling_interval, auto_update, @logger) @@ -140,6 +140,12 @@ def config @config end + def optimizely_config + @optimizely_config = OptimizelyConfig.new(@config).config if @optimizely_config.nil? + + @optimizely_config + end + private def fetch_datafile_config @@ -209,7 +215,9 @@ def set_config(config) end @config = config - @optimizely_config = OptimizelyConfig.new(config).config + + # clearing old optimizely config so that a fresh one is generated on the next api call. + @optimizely_config = nil @notification_center.send_notifications(NotificationCenter::NOTIFICATION_TYPES[:OPTIMIZELY_CONFIG_UPDATE]) diff --git a/lib/optimizely/config_manager/static_project_config_manager.rb b/lib/optimizely/config_manager/static_project_config_manager.rb index 2acff2e8..9196c282 100644 --- a/lib/optimizely/config_manager/static_project_config_manager.rb +++ b/lib/optimizely/config_manager/static_project_config_manager.rb @@ -23,7 +23,7 @@ module Optimizely class StaticProjectConfigManager < ProjectConfigManager # Implementation of ProjectConfigManager interface. - attr_reader :config, :optimizely_config + attr_reader :config def initialize(datafile, logger, error_handler, skip_json_validation) # Looks up and sets datafile and config based on response body. @@ -40,8 +40,13 @@ def initialize(datafile, logger, error_handler, skip_json_validation) error_handler, skip_json_validation ) + @optimizely_config = nil + end + + def optimizely_config + @optimizely_config = OptimizelyConfig.new(@config).config if @optimizely_config.nil? - @optimizely_config = @config.nil? ? nil : OptimizelyConfig.new(@config).config + @optimizely_config end end end From 7706e123448fb0d8fec5a604d55b7933cd69a401 Mon Sep 17 00:00:00 2001 From: Zeeshan Ashraf Date: Thu, 27 Jan 2022 18:51:47 -0800 Subject: [PATCH 2/2] updated copyright year --- lib/optimizely/config_manager/http_project_config_manager.rb | 2 +- lib/optimizely/config_manager/static_project_config_manager.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/optimizely/config_manager/http_project_config_manager.rb b/lib/optimizely/config_manager/http_project_config_manager.rb index 5b4f8727..7eceed76 100644 --- a/lib/optimizely/config_manager/http_project_config_manager.rb +++ b/lib/optimizely/config_manager/http_project_config_manager.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true # -# Copyright 2019-2020, Optimizely and contributors +# Copyright 2019-2020, 2022, Optimizely and contributors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/optimizely/config_manager/static_project_config_manager.rb b/lib/optimizely/config_manager/static_project_config_manager.rb index 9196c282..e5c3600f 100644 --- a/lib/optimizely/config_manager/static_project_config_manager.rb +++ b/lib/optimizely/config_manager/static_project_config_manager.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true # -# Copyright 2019-2020, Optimizely and contributors +# Copyright 2019-2020, 2022, Optimizely and contributors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License.