From 22d99227eaf9b86b489361aa8dda0b049d2e3115 Mon Sep 17 00:00:00 2001 From: Frank Schmid Date: Fri, 27 Jan 2023 14:02:19 +0100 Subject: [PATCH] Performance impact fix --- .../Internal/MqttClientSubscriptionsManager.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Source/MQTTnet/Server/Internal/MqttClientSubscriptionsManager.cs b/Source/MQTTnet/Server/Internal/MqttClientSubscriptionsManager.cs index b409d959f..70a5df880 100644 --- a/Source/MQTTnet/Server/Internal/MqttClientSubscriptionsManager.cs +++ b/Source/MQTTnet/Server/Internal/MqttClientSubscriptionsManager.cs @@ -403,23 +403,23 @@ static void FilterRetainedApplicationMessages( CreateSubscriptionResult createSubscriptionResult, SubscribeResult subscribeResult) { - for (var index = retainedMessages.Count - 1; index >= 0; index--) + if (createSubscriptionResult.Subscription.RetainHandling == MqttRetainHandling.DoNotSendOnSubscribe) { - var retainedMessage = retainedMessages[index]; - if (retainedMessage == null) - { - continue; + // This is a MQTT V5+ feature. + return; } - if (createSubscriptionResult.Subscription.RetainHandling == MqttRetainHandling.DoNotSendOnSubscribe) + if (createSubscriptionResult.Subscription.RetainHandling == MqttRetainHandling.SendAtSubscribeIfNewSubscriptionOnly && !createSubscriptionResult.IsNewSubscription) { // This is a MQTT V5+ feature. - continue; + return; } - if (createSubscriptionResult.Subscription.RetainHandling == MqttRetainHandling.SendAtSubscribeIfNewSubscriptionOnly && !createSubscriptionResult.IsNewSubscription) + for (var index = retainedMessages.Count - 1; index >= 0; index--) + { + var retainedMessage = retainedMessages[index]; + if (retainedMessage == null) { - // This is a MQTT V5+ feature. continue; }