Refactor and optimize envelope handling
Refactored `ReadDocumentDetailsQueryHandler` to remove AutoMapper, improving performance by manually selecting necessary data. Simplified `SenderEditorPage.razor` by removing bootstrap logic and updating the UI for a more compact design. Streamlined envelope creation in `SenderPage.razor` by eliminating the bootstrap token. Updated styles in `envelope-viewer.css` for better alignment and readability.
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
using AutoMapper;
|
||||
using AutoMapper.QueryableExtensions;
|
||||
using DigitalData.Core.Abstraction.Application.Repository;
|
||||
using EnvelopeGenerator.Application.Common.Dto;
|
||||
using EnvelopeGenerator.Domain.Entities;
|
||||
@@ -21,12 +19,10 @@ public record ReadDocumentDetailsQuery(int EnvelopeId, int? UserId = null) : IRe
|
||||
public class ReadDocumentDetailsQueryHandler : IRequestHandler<ReadDocumentDetailsQuery, DocumentDetailsDto?>
|
||||
{
|
||||
private readonly IRepository<Document> _repo;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public ReadDocumentDetailsQueryHandler(IRepository<Document> repo, IMapper mapper)
|
||||
public ReadDocumentDetailsQueryHandler(IRepository<Document> repo)
|
||||
{
|
||||
_repo = repo;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public async Task<DocumentDetailsDto?> Handle(ReadDocumentDetailsQuery query, CancellationToken cancel)
|
||||
@@ -36,9 +32,71 @@ public class ReadDocumentDetailsQueryHandler : IRequestHandler<ReadDocumentDetai
|
||||
if (query.UserId is int userId)
|
||||
docQuery = docQuery.Where(doc => doc.Envelope.UserId == userId);
|
||||
|
||||
return await docQuery
|
||||
// shortcut: manual select avoids AutoMapper ProjectTo pulling BYTE_DATA and the full navigation
|
||||
// graph (Envelope → History → User etc.) which caused an extremely slow query (~87s).
|
||||
// Annotations navigation is IEnumerable<T> on the entity (not ICollection<T>), so EF Core
|
||||
// cannot translate it in a Select projection — we skip it entirely here; sender editor only
|
||||
// needs element coordinates, not annotation payloads.
|
||||
var raw = await docQuery
|
||||
.Where(d => d.EnvelopeId == query.EnvelopeId)
|
||||
.ProjectTo<DocumentDetailsDto>(_mapper.ConfigurationProvider)
|
||||
.Select(d => new
|
||||
{
|
||||
d.Id,
|
||||
d.EnvelopeId,
|
||||
d.AddedWhen,
|
||||
Elements = d.Elements == null ? null : d.Elements.Select(e => new
|
||||
{
|
||||
e.Id,
|
||||
e.DocumentId,
|
||||
e.ReceiverId,
|
||||
e.ElementType,
|
||||
e.X,
|
||||
e.Y,
|
||||
e.Width,
|
||||
e.Height,
|
||||
e.Page,
|
||||
e.Required,
|
||||
e.Tooltip,
|
||||
e.ReadOnly,
|
||||
e.AnnotationIndex,
|
||||
e.AddedWhen,
|
||||
e.ChangedWhen,
|
||||
e.FullName,
|
||||
e.Position,
|
||||
e.Place,
|
||||
}).ToList()
|
||||
})
|
||||
.FirstOrDefaultAsync(cancel);
|
||||
|
||||
if (raw is null)
|
||||
return null;
|
||||
|
||||
return new DocumentDetailsDto
|
||||
{
|
||||
Id = raw.Id,
|
||||
EnvelopeId = raw.EnvelopeId,
|
||||
AddedWhen = raw.AddedWhen,
|
||||
Elements = raw.Elements?.Select(e => new DocReceiverElementDto
|
||||
{
|
||||
Id = e.Id,
|
||||
DocumentId = e.DocumentId,
|
||||
ReceiverId = e.ReceiverId,
|
||||
ElementType = e.ElementType,
|
||||
X = e.X,
|
||||
Y = e.Y,
|
||||
Width = e.Width,
|
||||
Height = e.Height,
|
||||
Page = e.Page,
|
||||
Required = e.Required,
|
||||
Tooltip = e.Tooltip,
|
||||
ReadOnly = e.ReadOnly,
|
||||
AnnotationIndex = e.AnnotationIndex,
|
||||
AddedWhen = e.AddedWhen,
|
||||
ChangedWhen = e.ChangedWhen,
|
||||
FullName = e.FullName,
|
||||
Position = e.Position,
|
||||
Place = e.Place,
|
||||
})
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user