Skip to content

Commit

Permalink
MMI-3071 Renamed more async methods
Browse files Browse the repository at this point in the history
  • Loading branch information
laidaoyu committed Nov 20, 2024
1 parent c2e9267 commit 1017b9e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
18 changes: 9 additions & 9 deletions libs/net/services/Helpers/ApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public async Task<T> HandleConcurrencyAsync<T>(Func<Task<T>> callbackDelegate)
public async Task<API.Areas.Editor.Models.Lookup.LookupModel?> GetLookupsAsync()
{
var response = await GetLookupsResponseAsync();
return await GetResponseData<API.Areas.Editor.Models.Lookup.LookupModel?>(response);
return await GetResponseDataAsync<API.Areas.Editor.Models.Lookup.LookupModel?>(response);
}
public async Task<HttpResponseMessage> GetLookupsResponseAsync()
{
Expand Down Expand Up @@ -290,7 +290,7 @@ public async Task<HttpResponseMessage> GetLookupsResponseWithEtagAsync(string et
public async Task<IEnumerable<API.Areas.Services.Models.Ingest.SourceModel>?> GetSourcesAsync()
{
var response = await GetSourcesResponseAsync();
return await GetResponseData<IEnumerable<API.Areas.Services.Models.Ingest.SourceModel>?>(response);
return await GetResponseDataAsync<IEnumerable<API.Areas.Services.Models.Ingest.SourceModel>?>(response);
}
public async Task<HttpResponseMessage> GetSourcesResponseWithEtagAsync(string etag)
{
Expand Down Expand Up @@ -348,7 +348,7 @@ public async Task<HttpResponseMessage> GetSourcesResponseAsync()
public async Task<IEnumerable<API.Areas.Services.Models.Ingest.IngestModel>?> GetIngestsAsync()
{
var response = await GetIngestsResponseAsync();
return await GetResponseData<IEnumerable<API.Areas.Services.Models.Ingest.IngestModel>?>(response);
return await GetResponseDataAsync<IEnumerable<API.Areas.Services.Models.Ingest.IngestModel>?>(response);
}
public async Task<HttpResponseMessage> GetIngestsResponseAsync()
{
Expand Down Expand Up @@ -1065,27 +1065,27 @@ public async Task<HttpResponseMessage> AddContentToFolderAsync(long contentId, i
/// Get all of the settings
/// </summary>
/// <returns></returns>
public async Task<T?> GetResponseData<T>(HttpResponseMessage response)
public async Task<T?> GetResponseDataAsync<T>(HttpResponseMessage response)
{
return await this.OpenClient.DeserializeAsync<T>(response);
}
public string? GetResponseEtag(HttpResponseMessage response)
{
return response.Headers.FirstOrDefault(x => x.Key == "ETag").Value?.ToList().FirstOrDefault();
}
public async Task<IEnumerable<API.Areas.Services.Models.Setting.SettingModel>?> GetSettings()
public async Task<IEnumerable<API.Areas.Services.Models.Setting.SettingModel>?> GetSettingsAsync()
{
var response = await GetSettingsResponse();
return await GetResponseData<IEnumerable<API.Areas.Services.Models.Setting.SettingModel>?>(response);
var response = await GetSettingsResponseAsync();
return await GetResponseDataAsync<IEnumerable<API.Areas.Services.Models.Setting.SettingModel>?>(response);
}

public async Task<HttpResponseMessage> GetSettingsResponse()
public async Task<HttpResponseMessage> GetSettingsResponseAsync()
{
var url = this.Options.ApiUrl.Append($"services/settings");
return await RetryRequestAsync(async () => await this.OpenClient.GetAsync(url));
}

public async Task<HttpResponseMessage> GetSettingsResponseWithEtag(string etag)
public async Task<HttpResponseMessage> GetSettingsResponseWithEtagAsync(string etag)
{
var url = this.Options.ApiUrl.Append($"services/settings");
return await RetryRequestAsync(async () => await this.OpenClient.GetAsync(url, etag));
Expand Down
8 changes: 4 additions & 4 deletions libs/net/services/Helpers/IApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -561,10 +561,10 @@ public Task<HttpResponseMessage> UploadFilesToS3Async(
/// Get all of the settings
/// </summary>
/// <returns></returns>
Task<IEnumerable<API.Areas.Services.Models.Setting.SettingModel>?> GetSettings();
Task<HttpResponseMessage> GetSettingsResponse();
Task<HttpResponseMessage> GetSettingsResponseWithEtag(string etag);
Task<IEnumerable<API.Areas.Services.Models.Setting.SettingModel>?> GetSettingsAsync();
Task<HttpResponseMessage> GetSettingsResponseAsync();
Task<HttpResponseMessage> GetSettingsResponseWithEtagAsync(string etag);
string? GetResponseEtag(HttpResponseMessage response);
Task<T?> GetResponseData<T>(HttpResponseMessage response);
Task<T?> GetResponseDataAsync<T>(HttpResponseMessage response);
#endregion
}
16 changes: 8 additions & 8 deletions services/net/content/ContentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ public override async Task RunAsync()
try
{
// TODO: Handle e-tag.
var ingest = (await GetIngests())?.ToArray();
var ingest = (await GetIngestsAsync())?.ToArray();

// Get settings to find any overrides.
var settings = await GetSettings();
var settings = await GetSettingsAsync();
var topicOverride = settings?.FirstOrDefault(s => s.Name == "ContentImportTopicOverride")?.Value.Split(",", StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries) ?? Array.Empty<string>();
var ingestTopics = ingest?
.Where(i => !String.IsNullOrWhiteSpace(i.Topic) && i.ImportContent())
Expand Down Expand Up @@ -323,7 +323,7 @@ private string FixHTMLIssues(string? text)
/// If the request failed, get the data from local memory cache.
/// </summary>
/// <returns></returns>
private Task<IEnumerable<API.Areas.Services.Models.Setting.SettingModel>?> GetSettings()
private Task<IEnumerable<API.Areas.Services.Models.Setting.SettingModel>?> GetSettingsAsync()
{
return GetLocalCacheListAsync<IEnumerable<API.Areas.Services.Models.Setting.SettingModel>>(SettingsListCacheKey);
}
Expand Down Expand Up @@ -393,7 +393,7 @@ private void UpdateEtagLocalCache(string keyName, string? etag)
/// <returns></returns>
private async Task<API.Areas.Services.Models.Ingest.IngestModel?> GetIngestsByTopicAsync(string topic)
{
return (await GetIngests())?.Where(x => x.Topic.ToUpperInvariant() == topic.ToUpperInvariant()).FirstOrDefault();
return (await GetIngestsAsync())?.Where(x => x.Topic.ToUpperInvariant() == topic.ToUpperInvariant()).FirstOrDefault();
}

/// <summary>
Expand All @@ -402,7 +402,7 @@ private void UpdateEtagLocalCache(string keyName, string? etag)
/// If the request failed, get the data from local memory cache.
/// </summary>
/// <returns></returns>
private Task<IEnumerable<API.Areas.Services.Models.Ingest.IngestModel>?> GetIngests()
private Task<IEnumerable<API.Areas.Services.Models.Ingest.IngestModel>?> GetIngestsAsync()
{
return GetLocalCacheListAsync<IEnumerable<API.Areas.Services.Models.Ingest.IngestModel>>(IngestServicesListCacheKey);
}
Expand Down Expand Up @@ -445,7 +445,7 @@ private void UpdateEtagLocalCache(string keyName, string? etag)
response = await this.Api.GetIngestsResponseWithEtagAsync(localEtagValue);
break;
case SettingsListCacheKey:
response = await this.Api.GetSettingsResponseWithEtag(localEtagValue);
response = await this.Api.GetSettingsResponseWithEtagAsync(localEtagValue);
break;
default:
break;
Expand All @@ -465,15 +465,15 @@ private void UpdateEtagLocalCache(string keyName, string? etag)
response = await this.Api.GetIngestsResponseAsync();
break;
case SettingsListCacheKey:
response = await this.Api.GetSettingsResponse();
response = await this.Api.GetSettingsResponseAsync();
break;
default:
break;
}
}
if (response != null && response.StatusCode == System.Net.HttpStatusCode.OK)
{
dataList = await this.Api.GetResponseData<T>(response);
dataList = await this.Api.GetResponseDataAsync<T>(response);
var etag = this.Api.GetResponseEtag(response);
UpdateEtagLocalCache(keyName, etag);
_memoryCache.Set(keyName, dataList, TimeSpan.FromMinutes(LocalCacheExpirationMinutes));
Expand Down

0 comments on commit 1017b9e

Please sign in to comment.