perf:根据指导建议优化性能

This commit is contained in:
hardstylewyl 2025-06-12 14:35:46 +08:00
parent 5e43bf37f8
commit c5695dda2f
14 changed files with 24 additions and 26 deletions

View File

@ -117,7 +117,7 @@ public class TrackDeleteEventHandler : ITransientDependency, ICapSubscribe
}
}
private bool CanDelete(TrackDeleteEvent @event)
private static bool CanDelete(TrackDeleteEvent @event)
{
if (@event.OrderIds == null)
return true;

View File

@ -372,7 +372,7 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
}
// 构建更新推送请求体
private TrackUpdateInput BuiltUpdateItem(TrackPushContentConfigDto config, TrackPushRecordIndex log)
private static TrackUpdateInput BuiltUpdateItem(TrackPushContentConfigDto config, TrackPushRecordIndex log)
{
var trackDatetime = log.TrackTime.AddHours(config.TrackTimeZone ?? log.TrackTimeZone - log.TrackTimeZone);
var trackDateStr = DateTimeFormat(trackDatetime, config.TrackTimeZone ?? log.TrackTimeZone, config);

View File

@ -130,7 +130,7 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe
}
}
private bool CanDelete(TrackUpsertEvent @event)
private static bool CanDelete(TrackUpsertEvent @event)
{
// 系统创建的轨迹不允许修改
if (@event.Visited.IsNullOrEmpty() && @event is { OperationMan: GlobalConst.SystemUser, IsAdd: false })
@ -383,7 +383,7 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe
}
private TrackDetailsIndex BuiltUpdateTrack(TrackUpsertEvent @event, TrackDetailsIndex track, OrderIdentifier order,
private static TrackDetailsIndex BuiltUpdateTrack(TrackUpsertEvent @event, TrackDetailsIndex track, OrderIdentifier order,
TrackContentVO trackContent)
{
//外部轨迹,轨迹发生地,轨迹发生时间,轨迹发生时区,不允许更改
@ -428,7 +428,7 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe
return track;
}
private TrackDetailsIndex BuiltNewTrack(TrackUpsertEvent @event, OrderIdentifier order, TrackContentVO trackContent)
private static TrackDetailsIndex BuiltNewTrack(TrackUpsertEvent @event, OrderIdentifier order, TrackContentVO trackContent)
{
var track = new TrackDetailsIndex
{
@ -483,7 +483,7 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe
return track;
}
private OrderOperationRecordIndex BuildOrderOperationRecord(TrackUpsertEvent @event, TrackDetailsIndex track, OrderIdentifier order)
private static OrderOperationRecordIndex BuildOrderOperationRecord(TrackUpsertEvent @event, TrackDetailsIndex track, OrderIdentifier order)
{
return new OrderOperationRecordIndex
{

View File

@ -49,7 +49,7 @@ public class TrackWarningCalcEventHandler : ITransientDependency, ICapSubscribe
await _forewarningNotifyService.WarningCalculateAsync(BuiltWarningDto(orders, @event));
}
private WarningDto BuiltWarningDto(List<OrderEntity> orders, TrackWarningCalcEvent @event)
private static WarningDto BuiltWarningDto(List<OrderEntity> orders, TrackWarningCalcEvent @event)
{
return new WarningDto
{

View File

@ -204,7 +204,7 @@ public class MySubscribeExecutor : ISubscribeExecutor
#region tracing
private long? TracingBefore(Message message, MethodInfo method)
private static long? TracingBefore(Message message, MethodInfo method)
{
if (s_diagnosticListener.IsEnabled(CapDiagnosticListenerNames.BeforeSubscriberInvoke))
{
@ -224,7 +224,7 @@ public class MySubscribeExecutor : ISubscribeExecutor
return null;
}
private void TracingAfter(long? tracingTimestamp, Message message, MethodInfo method)
private static void TracingAfter(long? tracingTimestamp, Message message, MethodInfo method)
{
CapEventCounterSource.Log.WriteInvokeMetrics();
if (tracingTimestamp != null &&
@ -244,7 +244,7 @@ public class MySubscribeExecutor : ISubscribeExecutor
}
}
private void TracingError(long? tracingTimestamp, Message message, MethodInfo? method, Exception ex)
private static void TracingError(long? tracingTimestamp, Message message, MethodInfo? method, Exception ex)
{
if (tracingTimestamp != null &&
s_diagnosticListener.IsEnabled(CapDiagnosticListenerNames.ErrorSubscriberInvoke))

View File

@ -1,6 +1,6 @@
namespace SJZY.Track.Application.CAP;
internal class SubscriberExecutionFailedException : Exception
internal sealed class SubscriberExecutionFailedException : Exception
{
private readonly Exception _originException;

View File

@ -476,7 +476,7 @@ public abstract class BasicCacheForPeriodicRefresh<TKey, TValue>
#endregion
private class CacheEntry
private sealed class CacheEntry
{
private static readonly DateTime NoExpire = DateTime.MaxValue;
public TValue? Data { get; set; }

View File

@ -30,16 +30,14 @@ public class StringHelper
public static string GetHash(string str)
{
// 将字符串转换为字节
byte[] data = Encoding.UTF8.GetBytes(str);
var data = Encoding.UTF8.GetBytes(str);
// 创建SHA256实例
using SHA256 sha256 = SHA256.Create();
// 计算哈希值
byte[] hash = sha256.ComputeHash(data);
var hash = SHA256.HashData(data);
// 将哈希值转换为16进制字符串
StringBuilder sb = new StringBuilder();
foreach (byte b in hash)
var sb = new StringBuilder();
foreach (var b in hash)
{
sb.Append(b.ToString("x2"));
}

View File

@ -148,7 +148,7 @@ public partial class OrderService : ApplicationService, IOrderService
}
private List<OrderPullStatusEntity> BuiltOrderPullStatus(List<PullConfigInfo>? pullConfigInfos)
private static List<OrderPullStatusEntity> BuiltOrderPullStatus(List<PullConfigInfo>? pullConfigInfos)
{
if (pullConfigInfos == null) return new List<OrderPullStatusEntity>();
@ -178,7 +178,7 @@ public partial class OrderService : ApplicationService, IOrderService
}).ToList();
}
private List<OrderPlatformNumberEntity> BuiltOrderPlatformNumbers(List<PullConfigInfo>? pullConfigInfos)
private static List<OrderPlatformNumberEntity> BuiltOrderPlatformNumbers(List<PullConfigInfo>? pullConfigInfos)
{
if (pullConfigInfos == null) return new List<OrderPlatformNumberEntity>();

View File

@ -375,7 +375,7 @@ public partial class TrackService
}
private class TrackIdxWarp
private sealed class TrackIdxWarp
{
public TrackDetail Track { get; set; }
public int Index { get; set; }
@ -388,7 +388,7 @@ public partial class TrackService
}
private class TrackWrap
private sealed class TrackWrap
{
public TrackDetail Track { get; set; }

View File

@ -312,7 +312,7 @@ public class TrackOrderService : ApplicationService
return (long) (time - sTime).TotalMilliseconds;
}
private string GetTimeZoneStr(float timeZone)
private static string GetTimeZoneStr(float timeZone)
{
var time = timeZone.ToString().Split('.');
if (time.Length > 1 && time[1] != "0") //如果时区有小数点

View File

@ -62,6 +62,6 @@ public class TrackPullCacheService : ITransientDependency, ITrackPullCacheServic
return data;
}
public string TrackPullContentKey(int subSystemId, string serviceProviderCode) =>
public static string TrackPullContentKey(int subSystemId, string serviceProviderCode) =>
$"{GlobalConst.TrackPullContentKeyPrefix}:{subSystemId}:{serviceProviderCode}";
}

View File

@ -39,7 +39,7 @@ public class TrackPushCacheService : ITrackPushCacheService, ITransientDependenc
return data;
}
private string TrackPushContentKey(int subSystemId, int customId) =>
private static string TrackPushContentKey(int subSystemId, int customId) =>
$"{GlobalConst.TrackPushContentKeyPrefix}:{subSystemId}:{customId}";
private async Task<List<TrackPushContentConfigDto>?> DoGetPushContentConfigsAsync(int subSystemId, int customId)

View File

@ -18,5 +18,5 @@ public partial class GlobalConst
public const string CapNoRetryErrorCode = "599";
public static DateTime MaxDateTime = new DateTime(2999, 1, 1, 0, 0, 0);
public static readonly DateTime MaxDateTime = new DateTime(2999, 1, 1, 0, 0, 0);
}