Spaces:
Sleeping
Sleeping
Commit ·
1b321bd
1
Parent(s): 0a579ad
feat: optimize canvas load and save using lazy loading and delta upserts
Browse files- FlowAPI.Application/DTOs/Graph/GraphDtos.cs +1 -0
- FlowAPI.Application/Interfaces/ITaskNodeService.cs +1 -0
- FlowAPI.Application/Services/GraphService.cs +19 -14
- FlowAPI.Application/Services/TaskNodeService.cs +6 -0
- FlowAPI.Infrastructure/Repositories/GraphRepository.cs +4 -1
- FlowAPI/Controllers/TaskNodesController.cs +12 -0
FlowAPI.Application/DTOs/Graph/GraphDtos.cs
CHANGED
|
@@ -33,6 +33,7 @@ namespace FlowAPI.Application.DTOs.Graph
|
|
| 33 |
public double? Width { get; set; }
|
| 34 |
public double? Height { get; set; }
|
| 35 |
public string? Data { get; set; }
|
|
|
|
| 36 |
}
|
| 37 |
|
| 38 |
public class EdgeDto
|
|
|
|
| 33 |
public double? Width { get; set; }
|
| 34 |
public double? Height { get; set; }
|
| 35 |
public string? Data { get; set; }
|
| 36 |
+
public bool? HasLargeData { get; set; }
|
| 37 |
}
|
| 38 |
|
| 39 |
public class EdgeDto
|
FlowAPI.Application/Interfaces/ITaskNodeService.cs
CHANGED
|
@@ -9,5 +9,6 @@ namespace FlowAPI.Application.Interfaces
|
|
| 9 |
Task<TaskNodeResponseDto> CreateAsync(CreateTaskNodeDto dto);
|
| 10 |
Task<TaskNodeResponseDto?> UpdateAsync(Guid id, UpdateTaskNodeDto dto);
|
| 11 |
Task<bool> DeleteAsync(Guid id);
|
|
|
|
| 12 |
}
|
| 13 |
}
|
|
|
|
| 9 |
Task<TaskNodeResponseDto> CreateAsync(CreateTaskNodeDto dto);
|
| 10 |
Task<TaskNodeResponseDto?> UpdateAsync(Guid id, UpdateTaskNodeDto dto);
|
| 11 |
Task<bool> DeleteAsync(Guid id);
|
| 12 |
+
Task<string?> GetNodeDataAsync(Guid id);
|
| 13 |
}
|
| 14 |
}
|
FlowAPI.Application/Services/GraphService.cs
CHANGED
|
@@ -113,21 +113,26 @@ namespace FlowAPI.Application.Services
|
|
| 113 |
CreatedAt = graph.CreatedAt,
|
| 114 |
IsShared = isShared,
|
| 115 |
Permission = permission,
|
| 116 |
-
Nodes = graph.Nodes.Select(n =>
|
| 117 |
{
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
}).ToList(),
|
| 132 |
Edges = graph.Edges.Select(e => new EdgeDto
|
| 133 |
{
|
|
|
|
| 113 |
CreatedAt = graph.CreatedAt,
|
| 114 |
IsShared = isShared,
|
| 115 |
Permission = permission,
|
| 116 |
+
Nodes = graph.Nodes.Select(n =>
|
| 117 |
{
|
| 118 |
+
bool hasLarge = n.Data != null && n.Data.Length > 2000;
|
| 119 |
+
return new NodeDto
|
| 120 |
+
{
|
| 121 |
+
Id = n.Id,
|
| 122 |
+
Label = n.Label,
|
| 123 |
+
PosX = n.PosX,
|
| 124 |
+
PosY = n.PosY,
|
| 125 |
+
Type = n.Type,
|
| 126 |
+
State = (int)n.State,
|
| 127 |
+
Decision = n.Decision,
|
| 128 |
+
Description = n.Description,
|
| 129 |
+
Color = n.Color,
|
| 130 |
+
IsPinned = n.IsPinned,
|
| 131 |
+
Width = n.Width,
|
| 132 |
+
Height = n.Height,
|
| 133 |
+
Data = hasLarge ? null : n.Data,
|
| 134 |
+
HasLargeData = hasLarge
|
| 135 |
+
};
|
| 136 |
}).ToList(),
|
| 137 |
Edges = graph.Edges.Select(e => new EdgeDto
|
| 138 |
{
|
FlowAPI.Application/Services/TaskNodeService.cs
CHANGED
|
@@ -67,6 +67,12 @@ namespace FlowAPI.Application.Services
|
|
| 67 |
return await _repo.DeleteAsync(id);
|
| 68 |
}
|
| 69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
private static TaskNodeResponseDto MapToDto(TaskNode node) => new()
|
| 71 |
{
|
| 72 |
Id = node.Id,
|
|
|
|
| 67 |
return await _repo.DeleteAsync(id);
|
| 68 |
}
|
| 69 |
|
| 70 |
+
public async Task<string?> GetNodeDataAsync(Guid id)
|
| 71 |
+
{
|
| 72 |
+
var node = await _repo.GetByIdAsync(id);
|
| 73 |
+
return node?.Data;
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
private static TaskNodeResponseDto MapToDto(TaskNode node) => new()
|
| 77 |
{
|
| 78 |
Id = node.Id,
|
FlowAPI.Infrastructure/Repositories/GraphRepository.cs
CHANGED
|
@@ -100,7 +100,10 @@ namespace FlowAPI.Infrastructure.Repositories
|
|
| 100 |
existingNode.IsPinned = node.IsPinned;
|
| 101 |
existingNode.Width = node.Width;
|
| 102 |
existingNode.Height = node.Height;
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
| 104 |
}
|
| 105 |
else
|
| 106 |
{
|
|
|
|
| 100 |
existingNode.IsPinned = node.IsPinned;
|
| 101 |
existingNode.Width = node.Width;
|
| 102 |
existingNode.Height = node.Height;
|
| 103 |
+
if (node.Data != null)
|
| 104 |
+
{
|
| 105 |
+
existingNode.Data = node.Data;
|
| 106 |
+
}
|
| 107 |
}
|
| 108 |
else
|
| 109 |
{
|
FlowAPI/Controllers/TaskNodesController.cs
CHANGED
|
@@ -59,5 +59,17 @@ namespace FlowAPI.Controllers
|
|
| 59 |
if (!result) return NotFound();
|
| 60 |
return NoContent();
|
| 61 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
}
|
| 63 |
}
|
|
|
|
| 59 |
if (!result) return NotFound();
|
| 60 |
return NoContent();
|
| 61 |
}
|
| 62 |
+
|
| 63 |
+
[HttpGet("{id:guid}/data")]
|
| 64 |
+
public async Task<ActionResult<object>> GetNodeData(Guid id)
|
| 65 |
+
{
|
| 66 |
+
var nodeData = await _service.GetNodeDataAsync(id);
|
| 67 |
+
if (nodeData is null)
|
| 68 |
+
{
|
| 69 |
+
var node = await _service.GetByIdAsync(id);
|
| 70 |
+
if (node is null) return NotFound();
|
| 71 |
+
}
|
| 72 |
+
return Ok(new { data = nodeData });
|
| 73 |
+
}
|
| 74 |
}
|
| 75 |
}
|