Просмотр исходного кода

refactor: disregard impossible case

Thales Macedo Garitezi 2 лет назад
Родитель
Сommit
60ae3c15c8
2 измененных файлов с 12 добавлено и 12 удалено
  1. 5 10
      apps/emqx/src/emqx_persistent_session_ds.erl
  2. 7 2
      apps/emqx/src/emqx_session.erl

+ 5 - 10
apps/emqx/src/emqx_persistent_session_ds.erl

@@ -146,16 +146,11 @@ del_subscription(IteratorID, TopicFilterBin, DSSessionID) ->
         begin
             TopicFilter = emqx_topic:words(TopicFilterBin),
             Ctx = #{iterator_id => IteratorID},
-            case IteratorID of
-                undefined ->
-                    ok;
-                _ ->
-                    ?tp_span(
-                        persistent_session_ds_close_iterators,
-                        Ctx,
-                        ok = ensure_iterator_closed_on_all_shards(IteratorID)
-                    )
-            end,
+            ?tp_span(
+                persistent_session_ds_close_iterators,
+                Ctx,
+                ok = ensure_iterator_closed_on_all_shards(IteratorID)
+            ),
             ?tp_span(
                 persistent_session_ds_iterator_delete,
                 Ctx,

+ 7 - 2
apps/emqx/src/emqx_session.erl

@@ -357,8 +357,13 @@ unsubscribe(
     session().
 remove_persistent_subscription(Session, TopicFilterBin, ClientId) ->
     Iterators = Session#session.iterators,
-    IteratorId = maps:get(TopicFilterBin, Iterators, undefined),
-    _ = emqx_persistent_session_ds:del_subscription(IteratorId, TopicFilterBin, ClientId),
+    case maps:get(TopicFilterBin, Iterators, undefined) of
+        undefined ->
+            ok;
+        IteratorId ->
+            _ = emqx_persistent_session_ds:del_subscription(IteratorId, TopicFilterBin, ClientId),
+            ok
+    end,
     Session#session{iterators = maps:remove(TopicFilterBin, Iterators)}.
 
 %%--------------------------------------------------------------------