Skip to content

Commit

Permalink
update acs GetTxQuota Method to async
Browse files Browse the repository at this point in the history
  • Loading branch information
area363 committed May 2, 2024
1 parent 29b4584 commit bb6ac46
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public AccessControlServiceController(IMutableAccessControlService accessControl
[HttpGet("entries/{address}")]
public ActionResult<int?> GetTxQuota(string address)
{
var result = _accessControlService.GetTxQuota(new Address(address));
var result = _accessControlService.GetTxQuotaAsync(new Address(address)).Result;

return result != null ? result : NotFound();
}
Expand Down
10 changes: 5 additions & 5 deletions NineChronicles.Headless/Services/RedisAccessControlService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Threading.Tasks;
using StackExchange.Redis;
using Libplanet.Crypto;
using Nekoyume.Blockchain;
Expand All @@ -23,18 +24,17 @@ public RedisAccessControlService(string storageUri)
_db = redis.GetDatabase();
}

public int? GetTxQuota(Address address)
public async Task<int?> GetTxQuotaAsync(Address address)
{
try
{
RedisValue result = _db.StringGet(address.ToString());

RedisValue result = await _db.StringGetAsync(address.ToString());
return !result.IsNull ? Convert.ToInt32(result) : null;
}
catch (RedisTimeoutException)
catch (RedisTimeoutException ex)
{
Log.ForContext("Source", nameof(IAccessControlService))
.Error("\"{Address}\" Redis timeout.", address);
.Error(ex, "\"{Address}\" Redis timeout encountered.", address);
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public RestAPIAccessControlService(string baseUrl)
};
}

public int? GetTxQuota(Address address)
public Task<int?> GetTxQuotaAsync(Address address)
{
try
{
Expand All @@ -31,7 +31,7 @@ public RestAPIAccessControlService(string baseUrl)
if (response.IsSuccessStatusCode)
{
string resultString = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
return Convert.ToInt32(resultString);
return Task.FromResult<int?>(Convert.ToInt32(resultString));
}
}
catch (TaskCanceledException)
Expand All @@ -45,7 +45,7 @@ public RestAPIAccessControlService(string baseUrl)
.Error(ex, "HttpRequestException occurred for \"{Address}\".", address);
}

return null;
return Task.FromResult<int?>(null);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Threading.Tasks;
using Microsoft.Data.Sqlite;
using Libplanet.Crypto;
using Nekoyume.Blockchain;
Expand Down Expand Up @@ -34,7 +35,7 @@ public SQLiteAccessControlService(string connectionString)
}
}

public int? GetTxQuota(Address address)
public Task<int?> GetTxQuotaAsync(Address address)
{
try
{
Expand All @@ -49,15 +50,15 @@ public SQLiteAccessControlService(string connectionString)

if (queryResult != null && queryResult != DBNull.Value)
{
return Convert.ToInt32(queryResult);
return Task.FromResult<int?>(Convert.ToInt32(queryResult));
}
}
catch (Exception ex)
{
Log.Error(ex, "An error occurred while getting transaction quota.");
}

return null;
return Task.FromResult<int?>(null);
}

private void ExecuteNonQuery(SqliteConnection connection, string commandText)
Expand Down

0 comments on commit bb6ac46

Please sign in to comment.