Skip to content

Commit e82a172

Browse files
tknsnail
authored andcommitted
perf: ⚡ 事件总线精简优化
1 parent c9e570f commit e82a172

31 files changed

+170
-287
lines changed

src/backend/GlobalUsings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
global using Gurion.DataValidation;
3333
global using Gurion.DependencyInjection;
3434
global using Gurion.DynamicApiController;
35-
global using Gurion.EventBus;
3635
global using Gurion.SpecificationDocument;
3736
global using Gurion.UnifyResult;
3837
global using Mapster;
@@ -58,6 +57,7 @@
5857
global using NetAdmin.Infrastructure.Configuration.Options.SubNodes.Upload;
5958
global using NetAdmin.Infrastructure.Constant;
6059
global using NetAdmin.Infrastructure.Enums;
60+
global using NetAdmin.Infrastructure.EventBus;
6161
global using NetAdmin.Infrastructure.Exceptions;
6262
global using NetAdmin.Infrastructure.Extensions;
6363
global using NetAdmin.Infrastructure.Languages;

src/backend/NetAdmin/NetAdmin.Domain/Dto/Sys/Cache/CacheStatisticsRsp.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ public sealed record CacheStatisticsRsp : DataAbstraction
1515
, new("redis_version:(.+)", RegexOptions.Compiled) //
1616
];
1717

18-
/// <summary>
19-
/// Initializes a new instance of the <see cref="CacheStatisticsRsp" /> class.
20-
/// </summary>
21-
public CacheStatisticsRsp() { }
22-
2318
/// <summary>
2419
/// Initializes a new instance of the <see cref="CacheStatisticsRsp" /> class.
2520
/// </summary>

src/backend/NetAdmin/NetAdmin.Domain/Dto/Sys/Cache/GetEntryRsp.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ namespace NetAdmin.Domain.Dto.Sys.Cache;
77
/// </summary>
88
public sealed record GetEntryRsp : DataAbstraction
99
{
10-
/// <summary>
11-
/// Initializes a new instance of the <see cref="GetEntryRsp" /> class.
12-
/// </summary>
13-
public GetEntryRsp() { }
14-
1510
/// <summary>
1611
/// 缓存值
1712
/// </summary>

src/backend/NetAdmin/NetAdmin.Domain/Dto/Sys/Menu/MetaInfo.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ namespace NetAdmin.Domain.Dto.Sys.Menu;
77
/// </summary>
88
public sealed record MetaInfo : DataAbstraction
99
{
10-
/// <summary>
11-
/// Initializes a new instance of the <see cref="MetaInfo" /> class.
12-
/// </summary>
13-
public MetaInfo() { }
14-
1510
/// <summary>
1611
/// Initializes a new instance of the <see cref="MetaInfo" /> class.
1712
/// </summary>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace NetAdmin.Domain.Events;
2+
3+
/// <summary>
4+
/// 事件数据
5+
/// </summary>
6+
public abstract record EventData<T> : DataAbstraction, IEventData<T>
7+
{
8+
/// <summary>
9+
/// Initializes a new instance of the <see cref="EventData{T}" /> class.
10+
/// </summary>
11+
protected EventData(T payLoad)
12+
{
13+
PayLoad = payLoad;
14+
}
15+
16+
/// <inheritdoc />
17+
public DateTime CreatedTime { get; init; } = DateTime.Now;
18+
19+
/// <inheritdoc />
20+
public T PayLoad { get; init; }
21+
}

src/backend/NetAdmin/NetAdmin.Domain/Events/IEventSourceGeneric.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/backend/NetAdmin/NetAdmin.Domain/Events/SeedDataInsertedEvent.cs

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,9 @@ namespace NetAdmin.Domain.Events;
33
/// <summary>
44
/// 种子数据插入完毕事件
55
/// </summary>
6-
public sealed record SeedDataInsertedEvent : DataAbstraction, IEventSource
6+
public sealed record SeedDataInsertedEvent : EventData<int>
77
{
8-
/// <summary>
9-
/// Initializes a new instance of the <see cref="SeedDataInsertedEvent" /> class.
10-
/// </summary>
11-
public SeedDataInsertedEvent(int insertedCount, bool isConsumeOnce = false)
12-
{
13-
IsConsumeOnce = isConsumeOnce;
14-
InsertedCount = insertedCount;
15-
CreatedTime = DateTime.Now;
16-
EventId = nameof(SeedDataInsertedEvent);
17-
}
18-
19-
/// <inheritdoc />
20-
public DateTime CreatedTime { get; }
21-
22-
/// <inheritdoc />
23-
public string EventId { get; }
24-
25-
/// <inheritdoc />
26-
public bool IsConsumeOnce { get; }
27-
28-
/// <inheritdoc />
29-
public CancellationToken CancellationToken { get; init; }
30-
31-
/// <summary>
32-
/// 插入数量
33-
/// </summary>
34-
public int InsertedCount { get; set; }
35-
368
/// <inheritdoc />
37-
public object Payload { get; init; }
9+
public SeedDataInsertedEvent(int payLoad) //
10+
: base(payLoad) { }
3811
}

src/backend/NetAdmin/NetAdmin.Domain/Events/SqlCommandAfterEvent.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ public SqlCommandAfterEvent(CommandAfterEventArgs e) //
1212
: base(e)
1313
{
1414
ElapsedMilliseconds = (long)((double)e.ElapsedTicks / Stopwatch.Frequency * 1_000);
15-
EventId = nameof(SqlCommandAfterEvent);
1615
}
1716

1817
/// <summary>
@@ -24,6 +23,6 @@ public SqlCommandAfterEvent(CommandAfterEventArgs e) //
2423
/// <inheritdoc />
2524
public override string ToString()
2625
{
27-
return string.Format(CultureInfo.InvariantCulture, "SQL-{0}: {2} ms {1}", Id, Sql, ElapsedMilliseconds);
26+
return string.Format(CultureInfo.InvariantCulture, "SQL-{0}: {2} ms {1}", Id, PayLoad, ElapsedMilliseconds);
2827
}
2928
}

src/backend/NetAdmin/NetAdmin.Domain/Events/SqlCommandBeforeEvent.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,8 @@ public record SqlCommandBeforeEvent : SqlCommandEvent
88
/// <summary>
99
/// Initializes a new instance of the <see cref="SqlCommandBeforeEvent" /> class.
1010
/// </summary>
11-
public SqlCommandBeforeEvent(CommandBeforeEventArgs e)
12-
{
13-
Identifier = e.Identifier;
14-
Sql = e.Command.ParameterFormat().RemoveWrapped();
15-
EventId = nameof(SqlCommandBeforeEvent);
16-
CreatedTime = DateTime.Now;
17-
}
11+
public SqlCommandBeforeEvent(CommandBeforeEventArgs e) //
12+
: base(e.Command.ParameterFormat().RemoveWrapped(), e.Identifier) { }
1813

1914
/// <inheritdoc />
2015
public override string ToString()

src/backend/NetAdmin/NetAdmin.Domain/Events/SqlCommandEvent.cs

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,17 @@ namespace NetAdmin.Domain.Events;
33
/// <summary>
44
/// Sql命令事件
55
/// </summary>
6-
public abstract record SqlCommandEvent : DataAbstraction, IEventSource
6+
public abstract record SqlCommandEvent : EventData<string>
77
{
88
/// <summary>
99
/// Initializes a new instance of the <see cref="SqlCommandEvent" /> class.
1010
/// </summary>
11-
protected SqlCommandEvent(bool isConsumeOnce = false)
11+
protected SqlCommandEvent(string payLoad, Guid identifier) //
12+
: base(payLoad)
1213
{
13-
IsConsumeOnce = isConsumeOnce;
14+
Identifier = identifier;
1415
}
1516

16-
/// <inheritdoc />
17-
public bool IsConsumeOnce { get; }
18-
19-
/// <inheritdoc />
20-
public CancellationToken CancellationToken { get; init; }
21-
22-
/// <inheritdoc />
23-
public DateTime CreatedTime { get; protected init; }
24-
25-
/// <inheritdoc />
26-
public string EventId { get; protected init; }
27-
28-
/// <inheritdoc />
29-
public object Payload { get; init; }
30-
3117
/// <summary>
3218
/// 标识符缩写
3319
/// </summary>
@@ -37,9 +23,4 @@ protected SqlCommandEvent(bool isConsumeOnce = false)
3723
/// 标识符,可将 CommandBefore 与 CommandAfter 进行匹配
3824
/// </summary>
3925
protected Guid Identifier { get; init; }
40-
41-
/// <summary>
42-
/// 关联的Sql语句
43-
/// </summary>
44-
protected string Sql { get; init; }
4526
}

0 commit comments

Comments
 (0)