From 69ec07cd610f434ce564f5913017767b6b457d4a Mon Sep 17 00:00:00 2001 From: kholodov Date: Fri, 11 Oct 2019 21:22:49 +0300 Subject: [PATCH 1/2] Do not reset the flowId / timestamp key if it is already set. --- .../Write/Special/Impl/Updater/FlowMessageUpdater.cs | 3 ++- .../Write/Special/Impl/Updater/TimestampUpdater.cs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/TeamCity.ServiceMessages/Write/Special/Impl/Updater/FlowMessageUpdater.cs b/TeamCity.ServiceMessages/Write/Special/Impl/Updater/FlowMessageUpdater.cs index 7226eba..ada6284 100644 --- a/TeamCity.ServiceMessages/Write/Special/Impl/Updater/FlowMessageUpdater.cs +++ b/TeamCity.ServiceMessages/Write/Special/Impl/Updater/FlowMessageUpdater.cs @@ -17,6 +17,7 @@ namespace JetBrains.TeamCity.ServiceMessages.Write.Special.Impl.Updater { using System; + using System.Linq; /// /// Service message updater that adds FlowId to service message according to @@ -45,7 +46,7 @@ public FlowMessageUpdater([NotNull] IFlowIdGenerator flowId) : this(flowId.NewFl public IServiceMessage UpdateServiceMessage(IServiceMessage message) { - return message.DefaultValue != null ? message : new PatchedServiceMessage(message) {{"flowId", FlowId}}; + return message.DefaultValue != null || message.Keys.Contains("flowId") ? message : new PatchedServiceMessage(message) {{"flowId", FlowId}}; } } } \ No newline at end of file diff --git a/TeamCity.ServiceMessages/Write/Special/Impl/Updater/TimestampUpdater.cs b/TeamCity.ServiceMessages/Write/Special/Impl/Updater/TimestampUpdater.cs index de7117d..fcdd72c 100644 --- a/TeamCity.ServiceMessages/Write/Special/Impl/Updater/TimestampUpdater.cs +++ b/TeamCity.ServiceMessages/Write/Special/Impl/Updater/TimestampUpdater.cs @@ -18,6 +18,7 @@ namespace JetBrains.TeamCity.ServiceMessages.Write.Special.Impl.Updater { using System; using System.Globalization; + using System.Linq; /// /// Service message updater that adds Timestamp to service message according to @@ -35,7 +36,7 @@ public TimestampUpdater([NotNull] Func timeService) public IServiceMessage UpdateServiceMessage(IServiceMessage message) { if (message == null) throw new ArgumentNullException(nameof(message)); - if (message.DefaultValue != null) return message; + if (message.DefaultValue != null || message.Keys.Contains("timestamp")) return message; return new PatchedServiceMessage(message) {{"timestamp", _timeService().ToUniversalTime().ToString("yyyy-MM-dd'T'HH:mm:ss.fff", CultureInfo.InvariantCulture) + "+0000"}}; } } From 34f7e8ee89fe2a9e63cc8651d5d1091507a82077 Mon Sep 17 00:00:00 2001 From: kholodov Date: Tue, 10 Dec 2019 13:28:14 +0300 Subject: [PATCH 2/2] performance improvement - replace Keys.Contains to GetValue --- .../Write/Special/Impl/Updater/FlowMessageUpdater.cs | 3 +-- .../Write/Special/Impl/Updater/TimestampUpdater.cs | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/TeamCity.ServiceMessages/Write/Special/Impl/Updater/FlowMessageUpdater.cs b/TeamCity.ServiceMessages/Write/Special/Impl/Updater/FlowMessageUpdater.cs index ada6284..66f2428 100644 --- a/TeamCity.ServiceMessages/Write/Special/Impl/Updater/FlowMessageUpdater.cs +++ b/TeamCity.ServiceMessages/Write/Special/Impl/Updater/FlowMessageUpdater.cs @@ -17,7 +17,6 @@ namespace JetBrains.TeamCity.ServiceMessages.Write.Special.Impl.Updater { using System; - using System.Linq; /// /// Service message updater that adds FlowId to service message according to @@ -46,7 +45,7 @@ public FlowMessageUpdater([NotNull] IFlowIdGenerator flowId) : this(flowId.NewFl public IServiceMessage UpdateServiceMessage(IServiceMessage message) { - return message.DefaultValue != null || message.Keys.Contains("flowId") ? message : new PatchedServiceMessage(message) {{"flowId", FlowId}}; + return message.DefaultValue != null || message.GetValue("flowId") != null ? message : new PatchedServiceMessage(message) { { "flowId", FlowId } }; } } } \ No newline at end of file diff --git a/TeamCity.ServiceMessages/Write/Special/Impl/Updater/TimestampUpdater.cs b/TeamCity.ServiceMessages/Write/Special/Impl/Updater/TimestampUpdater.cs index fcdd72c..9272866 100644 --- a/TeamCity.ServiceMessages/Write/Special/Impl/Updater/TimestampUpdater.cs +++ b/TeamCity.ServiceMessages/Write/Special/Impl/Updater/TimestampUpdater.cs @@ -36,7 +36,7 @@ public TimestampUpdater([NotNull] Func timeService) public IServiceMessage UpdateServiceMessage(IServiceMessage message) { if (message == null) throw new ArgumentNullException(nameof(message)); - if (message.DefaultValue != null || message.Keys.Contains("timestamp")) return message; + if (message.DefaultValue != null || message.GetValue("timestamp") != null) return message; return new PatchedServiceMessage(message) {{"timestamp", _timeService().ToUniversalTime().ToString("yyyy-MM-dd'T'HH:mm:ss.fff", CultureInfo.InvariantCulture) + "+0000"}}; } }