修复 RemoteConfig 接口中立即获取线上更新配置不生效的 BUG
--story=1021111 --user=yufei.hu 【中台】【Fix】修复 RemoteConfig 接口中立即获取线上更新配置不生效的 BUG https://www.tapd.cn/33527076/s/1159321 Signed-off-by: huyufei <yufei.hu@castbox.fm>dev
parent
2aad845378
commit
515c875ee8
|
|
@ -87,6 +87,8 @@ namespace Guru
|
|||
MinimumFetchInternalInMilliseconds = (ulong)(_fetchIntervalHours * 60 * 60 * 1000)
|
||||
});
|
||||
|
||||
_firebaseRemote.OnConfigUpdateListener += OnConfigUpdatedHandler;
|
||||
|
||||
// 设置默认值
|
||||
AppendDefaultValues(defaults);
|
||||
_initOnce = true;
|
||||
|
|
@ -94,7 +96,8 @@ namespace Guru
|
|||
// 监听事件合集
|
||||
_changeEvents = new Dictionary<string, Action<string,string>>(30);
|
||||
|
||||
FetchAllConfigs();
|
||||
// 立即拉取所有的配置
|
||||
FetchAllConfigsImmediately();
|
||||
}
|
||||
|
||||
private void AppendDefaultValues(Dictionary<string, object> defaults)
|
||||
|
|
@ -118,23 +121,121 @@ namespace Guru
|
|||
private void FetchAllConfigs(bool immediately = false)
|
||||
{
|
||||
var span = TimeSpan.FromHours(_fetchIntervalHours);
|
||||
if(_isDebug || immediately) span = TimeSpan.Zero;
|
||||
bool success = true;
|
||||
|
||||
// if (_isDebug || immediately)
|
||||
// {
|
||||
// FetchAllConfigsImmediately();
|
||||
// return;
|
||||
// }
|
||||
|
||||
if (_isDebug || immediately)
|
||||
{
|
||||
span = TimeSpan.Zero;
|
||||
}
|
||||
|
||||
_firebaseRemote.FetchAsync(span)
|
||||
.ContinueWithOnMainThread(task =>
|
||||
{
|
||||
bool success = true;
|
||||
if (task.IsFaulted || task.IsCanceled)
|
||||
{
|
||||
string res = task.IsFaulted? "Faulted" : "Canceled";
|
||||
LogE($" --- FetchAllConfigs fails: {res}");
|
||||
LogE($" --- Fetch AllConfigs fails: {res}");
|
||||
success = false;
|
||||
}
|
||||
|
||||
if (success) OnFetchDataCompleted();
|
||||
|
||||
if (success)
|
||||
{
|
||||
_firebaseRemote.ActivateAsync()
|
||||
.ContinueWithOnMainThread(task =>
|
||||
{
|
||||
if (task.IsFaulted || task.IsCanceled)
|
||||
{
|
||||
success = false;
|
||||
string res = task.IsFaulted? "Faulted" : "Canceled";
|
||||
LogE($" --- Active AllConfigs fails: {res}");
|
||||
}
|
||||
else
|
||||
{
|
||||
success = true;
|
||||
}
|
||||
LogI($"[REMOTE] --- ActiveAsync success: {success}");
|
||||
OnFetchDataCompleted();
|
||||
OnFetchCompleted?.Invoke(success);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
OnFetchDataCompleted();
|
||||
OnFetchCompleted?.Invoke(success);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 立即拉取所有的配置
|
||||
/// </summary>
|
||||
private void FetchAllConfigsImmediately()
|
||||
{
|
||||
bool success = true;
|
||||
_firebaseRemote.FetchAndActivateAsync()
|
||||
.ContinueWithOnMainThread(task =>
|
||||
{
|
||||
if (task.IsFaulted || task.IsCanceled)
|
||||
{
|
||||
success = false;
|
||||
string res = task.IsFaulted? "Faulted" : "Canceled";
|
||||
LogE($" --- Fetch AllConfigs fails: {res}");
|
||||
}
|
||||
else
|
||||
{
|
||||
success = true;
|
||||
LogI($"{Tag} --- FetchAndActivateAsync success");
|
||||
}
|
||||
LogI($"{Tag} --- FetchAndActivateAsync success: {success}");
|
||||
OnFetchDataCompleted();
|
||||
OnFetchCompleted?.Invoke(success);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取值更新回调
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="updateEvent"></param>
|
||||
private void OnConfigUpdatedHandler(object sender, ConfigUpdateEventArgs updateEvent)
|
||||
{
|
||||
if (updateEvent.Error != RemoteConfigError.None)
|
||||
{
|
||||
Debug.LogError($"{Tag} --- RemoteConfigError: {updateEvent.Error}");
|
||||
}
|
||||
else
|
||||
{
|
||||
_firebaseRemote.ActivateAsync().ContinueWithOnMainThread(task =>
|
||||
{
|
||||
if (task.IsCompleted)
|
||||
{
|
||||
if (updateEvent.UpdatedKeys != null)
|
||||
{
|
||||
var updateKeys = updateEvent.UpdatedKeys.ToArray();
|
||||
string key = "";
|
||||
int i = 0;
|
||||
int count = updateEvent.UpdatedKeys.Count();
|
||||
while (i < count)
|
||||
{
|
||||
key = updateEvent.UpdatedKeys.ElementAt(i);
|
||||
if (_changeEvents.TryGetValue(updateKeys[i], out var callback))
|
||||
{
|
||||
callback?.Invoke(key, _firebaseRemote.GetValue(key).StringValue);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
|
|
|||
Loading…
Reference in New Issue