[성현모] HubX DB구조, 쿼리 개선

This commit is contained in:
SHM
2025-04-24 08:56:44 +09:00
parent 7a69ea7ea2
commit 0a6016bc95
8 changed files with 21 additions and 26 deletions

View File

@ -21,7 +21,7 @@ namespace HubX.Server.Services
_scopeFactory = scopeFactory;
}
public async Task<Response_InsertUniqueKy> Request_InsertUniqueKey(Request_InsertUniqueKey request)
public async Task<Response_InsertUniqueKy> Request_InsertUniqueKey(Request_InsertUniqueKey request, string guid = "")
{
Response_InsertUniqueKy response = new Response_InsertUniqueKy();
@ -35,10 +35,10 @@ namespace HubX.Server.Services
var context = scope.ServiceProvider.GetRequiredService<HubXContext>();
if (context != null)
{
var data = context.TStorages.AsNoTracking().Where(x => x.CIdentity == request.Identity).ToList();
var data = await context.TStorages.AsNoTracking().Where(x => x.CIdentity == request.Identity).ToListAsync();
if (data?.Count() > 0)
{
Log4net.WriteLine($"Exist Unique Key", LogType.Error);
Log4net.WriteLine($"Exist Unique Key::{guid}", LogType.Error);
response.Result = "Exist Unique Key";
}
else
@ -64,7 +64,7 @@ namespace HubX.Server.Services
if (transactionResult == false)
{
response.Result = EnumResult.Failed.ToString();
Log4net.WriteLine($"Transaction Error", LogType.Error);
Log4net.WriteLine($"Transaction Error::{guid}", LogType.Error);
}
else
{
@ -78,7 +78,7 @@ namespace HubX.Server.Services
return response;
}
public async Task<Response_SelectUniqueKy> Request_SelectUniqueKey(Request_SelectUniqueKey request)
public async Task<Response_SelectUniqueKy> Request_SelectUniqueKey(Request_SelectUniqueKey request, string guid = "")
{
Response_SelectUniqueKy response = new Response_SelectUniqueKy();
@ -94,7 +94,7 @@ namespace HubX.Server.Services
{
using (var transaction = await context.CreateTransactionAsync(IsolationLevel.ReadUncommitted))
{
var data = context.TStorages.AsNoTracking().ToList().First(x => x.CIdentity == request.Identity);
var data = await context.TStorages.AsNoTracking().FirstOrDefaultAsync(x => x.CIdentity == request.Identity);
await context.CloseTransactionAsync(transaction);
if (data != null)
{
@ -108,7 +108,7 @@ namespace HubX.Server.Services
}
catch (Exception e)
{
Log4net.WriteLine($"Select Unique Key Transaction Error", LogType.Error);
Log4net.WriteLine($"Select Unique Key Transaction Error::{guid}", LogType.Error);
Log4net.WriteLine(e);
}
}
@ -118,7 +118,7 @@ namespace HubX.Server.Services
return response;
}
public async Task<Response_UpdateUniqueKy> Request_UpdateUniqueKey(Request_UpdateUniqueKey request)
public async Task<Response_UpdateUniqueKy> Request_UpdateUniqueKey(Request_UpdateUniqueKey request, string guid = "")
{
Response_UpdateUniqueKy response = new Response_UpdateUniqueKy();
@ -133,7 +133,7 @@ namespace HubX.Server.Services
var context = scope.ServiceProvider.GetRequiredService<HubXContext>();
if (context != null)
{
var selected = context.TStorages.First(x => x.CIdentity == request.Identity);
var selected = await context.TStorages.FirstOrDefaultAsync(x => x.CIdentity == request.Identity);
if (selected != null)
{
selected.CData1 = request.Data1;
@ -154,7 +154,7 @@ namespace HubX.Server.Services
if (transactionResult == false)
{
response.Result = EnumResult.Failed.ToString();
Log4net.WriteLine($"Transaction Error", LogType.Error);
Log4net.WriteLine($"Transaction Error::{guid}", LogType.Error);
}
else
{