forked from ddrilling/AsbCloudServer
CS2-50: Added .AsNoTracking() to services' queries.
This commit is contained in:
parent
814f809c3e
commit
744266336e
@ -482,7 +482,7 @@ namespace AsbCloudDb.Model
|
|||||||
{
|
{
|
||||||
From = g.Min(d => d.Date),
|
From = g.Min(d => d.Date),
|
||||||
To = g.Max(d => d.Date)
|
To = g.Max(d => d.Date)
|
||||||
}).FirstOrDefault();
|
}).AsNoTracking().FirstOrDefault();
|
||||||
|
|
||||||
if (datesRange is null)
|
if (datesRange is null)
|
||||||
return (DateTime.MinValue, DateTime.MaxValue);
|
return (DateTime.MinValue, DateTime.MaxValue);
|
||||||
|
@ -57,7 +57,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
WellDepth = d.WellDepth ?? 0.0,
|
WellDepth = d.WellDepth ?? 0.0,
|
||||||
BitDepth = d.BitDepth ?? 0.0,
|
BitDepth = d.BitDepth ?? 0.0,
|
||||||
Date = d.Date
|
Date = d.Date
|
||||||
}).ToList();
|
}).AsNoTracking().ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<WellDepthToIntervalDto> GetWellDepthToInterval(int idWell,
|
public IEnumerable<WellDepthToIntervalDto> GetWellDepthToInterval(int idWell,
|
||||||
@ -125,7 +125,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
if (skip > 0)
|
if (skip > 0)
|
||||||
operations = operations.Skip(skip);
|
operations = operations.Skip(skip);
|
||||||
|
|
||||||
var operationsList = operations.Take(take).ToList();
|
var operationsList = operations.Take(take).AsNoTracking().ToList();
|
||||||
|
|
||||||
if (operationsList.Count == 0)
|
if (operationsList.Count == 0)
|
||||||
return result;
|
return result;
|
||||||
@ -169,7 +169,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
OperationName = g.Key.Name,
|
OperationName = g.Key.Name,
|
||||||
Duration = g.Where(g => g.DurationSec > 0)
|
Duration = g.Where(g => g.DurationSec > 0)
|
||||||
.Sum(a => a.DurationSec)
|
.Sum(a => a.DurationSec)
|
||||||
}).ToList();
|
}).AsNoTracking().ToList();
|
||||||
|
|
||||||
return operations;
|
return operations;
|
||||||
}
|
}
|
||||||
@ -200,7 +200,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
IntervalStart = g.Min(d => d.UnixDate),
|
IntervalStart = g.Min(d => d.UnixDate),
|
||||||
OperationName = g.Key.Name,
|
OperationName = g.Key.Name,
|
||||||
OperationsDuration = g.Sum(an => an.DurationSec)
|
OperationsDuration = g.Sum(an => an.DurationSec)
|
||||||
}).ToList();
|
}).AsNoTracking().ToList();
|
||||||
|
|
||||||
var operationsGroupedByInterval = operations.GroupBy(op => op.IntervalStart)
|
var operationsGroupedByInterval = operations.GroupBy(op => op.IntervalStart)
|
||||||
.Select(o => new TelemetryOperationInfoDto
|
.Select(o => new TelemetryOperationInfoDto
|
||||||
|
@ -9,6 +9,7 @@ using System.Linq;
|
|||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace AsbCloudInfrastructure.Services
|
namespace AsbCloudInfrastructure.Services
|
||||||
{
|
{
|
||||||
@ -97,7 +98,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
|
|
||||||
public int ChangePassword(string userLogin, string newPassword)
|
public int ChangePassword(string userLogin, string newPassword)
|
||||||
{
|
{
|
||||||
var user = db.Users.FirstOrDefault(u => u.Login == userLogin);
|
var user = db.Users.AsNoTracking().FirstOrDefault(u => u.Login == userLogin);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@ -138,6 +139,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
{
|
{
|
||||||
var user = db
|
var user = db
|
||||||
.GetUsersByLogin(login)
|
.GetUsersByLogin(login)
|
||||||
|
.AsNoTracking()
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
|
|
||||||
if (user is null)
|
if (user is null)
|
||||||
|
@ -24,7 +24,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
.Include(w => w.Cluster)
|
.Include(w => w.Cluster)
|
||||||
.ThenInclude(c => c.Deposit)
|
.ThenInclude(c => c.Deposit)
|
||||||
where well.RelationCompaniesWells.Any(r => r.IdCompany == idCompany)
|
where well.RelationCompaniesWells.Any(r => r.IdCompany == idCompany)
|
||||||
select well).ToList();
|
select well).AsNoTracking().ToList();
|
||||||
|
|
||||||
var gDepositEntities = wellEntities
|
var gDepositEntities = wellEntities
|
||||||
.GroupBy(w => w.Cluster)
|
.GroupBy(w => w.Cluster)
|
||||||
@ -65,6 +65,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
var entities = db.GetWellsForCompany(idCompany)
|
var entities = db.GetWellsForCompany(idCompany)
|
||||||
.Select(e => e.Cluster)
|
.Select(e => e.Cluster)
|
||||||
.Distinct()
|
.Distinct()
|
||||||
|
.AsNoTracking()
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
var dtos = entities.Select(e => new ClusterDto
|
var dtos = entities.Select(e => new ClusterDto
|
||||||
@ -84,6 +85,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
.Select(e => e.Cluster)
|
.Select(e => e.Cluster)
|
||||||
.Where(e => e.IdDeposit == depositId)
|
.Where(e => e.IdDeposit == depositId)
|
||||||
.Distinct()
|
.Distinct()
|
||||||
|
.AsNoTracking()
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
var dtos = entities.Select(e => new ClusterDto
|
var dtos = entities.Select(e => new ClusterDto
|
||||||
@ -101,6 +103,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
{
|
{
|
||||||
var entities = db.GetWellsForCompany(idCompany)
|
var entities = db.GetWellsForCompany(idCompany)
|
||||||
.Where(e => e.IdCluster == idCluster)
|
.Where(e => e.IdCluster == idCluster)
|
||||||
|
.AsNoTracking()
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
var dtos = entities.Select(e => new WellDto
|
var dtos = entities.Select(e => new WellDto
|
||||||
@ -164,12 +167,12 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
CompanyType = c.Company.CompanyType.Caption,
|
CompanyType = c.Company.CompanyType.Caption,
|
||||||
}),
|
}),
|
||||||
WellType = e.WellType.Caption,
|
WellType = e.WellType.Caption,
|
||||||
}).ToList();
|
}).AsNoTracking().ToList();
|
||||||
|
|
||||||
if (!wellStatDtos.Any())
|
if (!wellStatDtos.Any())
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
var clusterById = db.Clusters.FirstOrDefault(c => c.Id == idCluster);
|
var clusterById = db.Clusters.AsNoTracking().FirstOrDefault(c => c.Id == idCluster);
|
||||||
|
|
||||||
return new ClusterStatDto
|
return new ClusterStatDto
|
||||||
{
|
{
|
||||||
|
@ -24,7 +24,8 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
|
|
||||||
public virtual async Task<Tdto> GetAsync(int id, CancellationToken token = default)
|
public virtual async Task<Tdto> GetAsync(int id, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
var entity = await dbSet.FirstOrDefaultAsync(e => e.Id == id, token).ConfigureAwait(false);
|
var entity = await dbSet.AsNoTracking()
|
||||||
|
.FirstOrDefaultAsync(e => e.Id == id, token).ConfigureAwait(false);
|
||||||
var dto = entity.Adapt<Tdto>();
|
var dto = entity.Adapt<Tdto>();
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
@ -59,7 +60,8 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
|
|
||||||
public virtual Task<int> DeleteAsync(int id, CancellationToken token = default)
|
public virtual Task<int> DeleteAsync(int id, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
var entity = dbSet.FirstOrDefault(e => e.Id == id);
|
var entity = dbSet.AsNoTracking()
|
||||||
|
.FirstOrDefault(e => e.Id == id);
|
||||||
if (entity == default)
|
if (entity == default)
|
||||||
return Task.FromResult(0);
|
return Task.FromResult(0);
|
||||||
dbSet.Remove(entity);
|
dbSet.Remove(entity);
|
||||||
@ -68,7 +70,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
|
|
||||||
public virtual Task<int> DeleteAsync(IEnumerable<int> ids, CancellationToken token = default)
|
public virtual Task<int> DeleteAsync(IEnumerable<int> ids, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
var entities = dbSet.Where(e => ids.Contains(e.Id));
|
var entities = dbSet.Where(e => ids.Contains(e.Id)).AsNoTracking();
|
||||||
if (entities == default)
|
if (entities == default)
|
||||||
return Task.FromResult(0);
|
return Task.FromResult(0);
|
||||||
dbSet.RemoveRange(entities);
|
dbSet.RemoveRange(entities);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
using AsbCloudDb.Model;
|
using AsbCloudDb.Model;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using AsbCloudInfrastructure.Services.Cache;
|
using AsbCloudInfrastructure.Services.Cache;
|
||||||
using Mapster;
|
using Mapster;
|
||||||
using System;
|
using System;
|
||||||
@ -59,7 +60,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
query = query.Where(d => d.Id % m == 0);
|
query = query.Where(d => d.Id % m == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
var entities = query.ToList();
|
var entities = query.AsNoTracking().ToList();
|
||||||
|
|
||||||
var dtos = entities.Adapt<DataSaubBaseDto>();
|
var dtos = entities.Adapt<DataSaubBaseDto>();
|
||||||
|
|
||||||
@ -79,7 +80,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
where d.IdTelemetry == telemetryId
|
where d.IdTelemetry == telemetryId
|
||||||
&& d.Date > dtoMinDate
|
&& d.Date > dtoMinDate
|
||||||
&& d.Date < dtoMaxDate
|
&& d.Date < dtoMaxDate
|
||||||
select d).ToList();
|
select d).AsNoTracking().ToList();
|
||||||
|
|
||||||
if (oldDataSaubBase.Any())
|
if (oldDataSaubBase.Any())
|
||||||
db.DataSaubBases.RemoveRange(oldDataSaubBase);
|
db.DataSaubBases.RemoveRange(oldDataSaubBase);
|
||||||
|
@ -49,7 +49,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
{
|
{
|
||||||
var filesInfoQuery = db.Files.Include(f => f.User)
|
var filesInfoQuery = db.Files.Include(f => f.User)
|
||||||
.Where(f => f.IdWell == idWell &&
|
.Where(f => f.IdWell == idWell &&
|
||||||
f.IdCategory == idCategory);
|
f.IdCategory == idCategory).AsNoTracking();
|
||||||
|
|
||||||
if (!filesInfoQuery.Any())
|
if (!filesInfoQuery.Any())
|
||||||
return null;
|
return null;
|
||||||
@ -57,15 +57,15 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
var result = new PaginationContainer<FilePropertiesDto>() { Skip = skip, Take = take };
|
var result = new PaginationContainer<FilePropertiesDto>() { Skip = skip, Take = take };
|
||||||
|
|
||||||
if (begin != default)
|
if (begin != default)
|
||||||
filesInfoQuery = filesInfoQuery.Where(m => m.Date >= begin);
|
filesInfoQuery = filesInfoQuery.Where(m => m.Date >= begin).AsNoTracking();
|
||||||
|
|
||||||
if (end != default)
|
if (end != default)
|
||||||
filesInfoQuery = filesInfoQuery.Where(m => m.Date <= end);
|
filesInfoQuery = filesInfoQuery.Where(m => m.Date <= end).AsNoTracking();
|
||||||
|
|
||||||
result.Count = filesInfoQuery.Count();
|
result.Count = filesInfoQuery.Count();
|
||||||
|
|
||||||
if (skip > 0)
|
if (skip > 0)
|
||||||
filesInfoQuery = filesInfoQuery.Skip(skip);
|
filesInfoQuery = filesInfoQuery.Skip(skip).AsNoTracking();
|
||||||
|
|
||||||
var filesInfoList = filesInfoQuery.OrderBy(f => f.Date).Take(take).ToList();
|
var filesInfoList = filesInfoQuery.OrderBy(f => f.Date).Take(take).ToList();
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
|
|
||||||
public (int Id, string Name, int IdCategory)? GetFileInfo(int fileId)
|
public (int Id, string Name, int IdCategory)? GetFileInfo(int fileId)
|
||||||
{
|
{
|
||||||
var fileInfo = db.Files.FirstOrDefault(f => f.Id == fileId);
|
var fileInfo = db.Files.AsNoTracking().FirstOrDefault(f => f.Id == fileId);
|
||||||
|
|
||||||
if (fileInfo is null)
|
if (fileInfo is null)
|
||||||
return null;
|
return null;
|
||||||
|
@ -3,6 +3,7 @@ using AsbCloudDb.Model;
|
|||||||
using Mapster;
|
using Mapster;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace AsbCloudInfrastructure.Services
|
namespace AsbCloudInfrastructure.Services
|
||||||
{
|
{
|
||||||
@ -17,7 +18,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
|
|
||||||
public Tdto Get(int idWell, int idCategory)
|
public Tdto Get(int idWell, int idCategory)
|
||||||
{
|
{
|
||||||
var entity = db.LastData.FirstOrDefault(e =>
|
var entity = db.LastData.AsNoTracking().FirstOrDefault(e =>
|
||||||
e.IdWell == idWell && e.IdCategory == idCategory);
|
e.IdWell == idWell && e.IdCategory == idCategory);
|
||||||
|
|
||||||
if (entity is null)
|
if (entity is null)
|
||||||
@ -31,7 +32,8 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
{
|
{
|
||||||
var model = value.Adapt<TModel>();
|
var model = value.Adapt<TModel>();
|
||||||
|
|
||||||
var entity = db.LastData.FirstOrDefault(ld => ld.IdWell == idWell &&
|
var entity = db.LastData.AsNoTracking()
|
||||||
|
.FirstOrDefault(ld => ld.IdWell == idWell &&
|
||||||
ld.IdCategory == idCategory);
|
ld.IdCategory == idCategory);
|
||||||
|
|
||||||
if (entity is not null)
|
if (entity is not null)
|
||||||
|
@ -79,7 +79,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
if (skip > 0)
|
if (skip > 0)
|
||||||
query = query.Skip(skip);
|
query = query.Skip(skip);
|
||||||
|
|
||||||
var messagesList = query.Take(take).ToList();
|
var messagesList = query.Take(take).AsNoTracking().ToList();
|
||||||
|
|
||||||
if (messagesList.Count == 0)
|
if (messagesList.Count == 0)
|
||||||
return result;
|
return result;
|
||||||
|
@ -29,7 +29,8 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
this.telemetryService = telemetryService;
|
this.telemetryService = telemetryService;
|
||||||
this.fileService = fileService;
|
this.fileService = fileService;
|
||||||
this.queue = queue;
|
this.queue = queue;
|
||||||
ReportCategoryId = db.FileCategories.FirstOrDefault(c =>
|
ReportCategoryId = db.FileCategories.AsNoTracking()
|
||||||
|
.FirstOrDefault(c =>
|
||||||
c.Name.Equals("Рапорт")).Id;
|
c.Name.Equals("Рапорт")).Id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,12 +122,15 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
select d.Date).Union(
|
select d.Date).Union(
|
||||||
from m in db.TelemetryMessages
|
from m in db.TelemetryMessages
|
||||||
where m.IdTelemetry == telemetryId
|
where m.IdTelemetry == telemetryId
|
||||||
select m.Date).DefaultIfEmpty().GroupBy(g => true)
|
select m.Date).DefaultIfEmpty()
|
||||||
|
.GroupBy(g => true)
|
||||||
|
.AsNoTracking()
|
||||||
.Select(g => new
|
.Select(g => new
|
||||||
{
|
{
|
||||||
From = g.Min(),
|
From = g.Min(),
|
||||||
To = g.Max()
|
To = g.Max()
|
||||||
}).OrderBy(gr => gr.From).FirstOrDefault();
|
}).OrderBy(gr => gr.From)
|
||||||
|
.FirstOrDefault();
|
||||||
|
|
||||||
return new DatesRangeDto
|
return new DatesRangeDto
|
||||||
{
|
{
|
||||||
@ -144,6 +148,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
&& r.Step <= stepSeconds
|
&& r.Step <= stepSeconds
|
||||||
&& r.Format == format
|
&& r.Format == format
|
||||||
select r).OrderBy(o => o.File.Date)
|
select r).OrderBy(o => o.File.Date)
|
||||||
|
.AsNoTracking()
|
||||||
.Take(512).ToList();
|
.Take(512).ToList();
|
||||||
|
|
||||||
return suitableReportsNames;
|
return suitableReportsNames;
|
||||||
|
@ -4,7 +4,6 @@ using AsbCloudDb.Model;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using Mapster;
|
using Mapster;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
@ -6,6 +6,7 @@ using Mapster;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace AsbCloudInfrastructure.Services
|
namespace AsbCloudInfrastructure.Services
|
||||||
{
|
{
|
||||||
@ -30,6 +31,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
{
|
{
|
||||||
wells = db.GetWellsForCompany(idCompany)
|
wells = db.GetWellsForCompany(idCompany)
|
||||||
.Where(w => activeTelemetriesUids.Contains(w.Telemetry.RemoteUid))
|
.Where(w => activeTelemetriesUids.Contains(w.Telemetry.RemoteUid))
|
||||||
|
.AsNoTracking()
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
return wells.Select(w => From(w));
|
return wells.Select(w => From(w));
|
||||||
@ -49,6 +51,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
var entities = db
|
var entities = db
|
||||||
.WellOperations
|
.WellOperations
|
||||||
.Where(o => o.IdWell == idWell)
|
.Where(o => o.IdWell == idWell)
|
||||||
|
.AsNoTracking()
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
var dtos = entities.Adapt<WellOperationDto>();
|
var dtos = entities.Adapt<WellOperationDto>();
|
||||||
|
Loading…
Reference in New Issue
Block a user