anchor.diff:      qos1 = dict:new()         ,
       qos2 = dict:new()         ,
       qos2_rec = gb_sets:new()  ,
  -    refs = gb_sets:new()
  -%%     subs = orddict:new()      ,
  +    refs = gb_sets:new()      ,
  +    subs = orddict:new()
   %%     min_subs = orddict:new()
   }).
   
  
positive.code: %% SUBSCRIPTIONS
  %% ================================================================================
  
  subscribe(S =#session_out{ client_id = ClientId},NewSubs) ->
  
      %% Maintain a flat list of subscriptions
  %%     Subs1 = lists:foldr(fun({Topic,QoS},Acc) ->
  %%                                 orddict:store(Topic,QoS,Acc)
  %%                               end,
  %%                              Subs, NewSubs),
  %%     MinCover = mqtt_topic:min_cover(orddict:to_list(Subs1)),
  %%     _MinCover =
      [
          begin
              error_logger:info_msg("Subscribing: ~p,~p,~p,~n",[ClientId,Topic,QoS]),
              mqtt_sub_repo:add_sub(ClientId,Topic,QoS)
          end
          || {Topic,QoS} <- NewSubs
      ]
      
      %% S#session_out{subs = Subs1, min_subs = MinCover}
      %% @todo: Deduplicate, persist
  .
  
  unsubscribe(S = #session_out{subs = Subs, client_id = ClientId},OldSubs) ->
      [
          mqtt_sub_repo:remove_sub(ClientId,Topic)
          || Topic <- Subs
      ]
  %%     S#session_out{subs =
  %%                   lists:foldr(fun(Topic,Acc) ->
  %%                                 orddict:erase(Topic,Acc)
  %%                               end,
  %%                               Subs, OldSubs)}
      %% @todo: Deduplicate, persist
      .
  
  %% get_sub_diff(Subs,NewSubs) ->
  %%     orddict:update().
  
negative.code: %%     end
  
  
  %% clear persisted data during shutdown
  cleanup(S = #session_out{client_id = ClientId}) ->
      mqtt_reg_repo:unregister(ClientId),
      maybe_clear_subs(S).
  
  maybe_clear_subs(#session_out{subs = Subs, client_id = ClientId, is_persistent = true}) ->
      [ mqtt_sub_repo:remove_sub(ClientId,Topic) || {Topic,_QoS}  <- Subs ],
      ok;
  
  maybe_clear_subs(_S) ->
      ok.
  
  
  
  %%add_or_replace_sub(ClientId,{Topic,QoS},Subs)->
  