mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
Use more efficient way to calculate changes in set_privacy_list
This commit is contained in:
parent
d95a1bac3e
commit
8e64992f47
@ -422,6 +422,12 @@ set_privacy_list_new(ID, RItems) ->
|
|||||||
end,
|
end,
|
||||||
RItems).
|
RItems).
|
||||||
|
|
||||||
|
calculate_difference(List1, List2) ->
|
||||||
|
Set1 = gb_sets:from_list(List1),
|
||||||
|
Set2 = gb_sets:from_list(List2),
|
||||||
|
{gb_sets:subtract(Set1, Set2),
|
||||||
|
gb_sets:subtract(Set2, Set1)}.
|
||||||
|
|
||||||
set_privacy_list(ID, RItems) ->
|
set_privacy_list(ID, RItems) ->
|
||||||
case ejabberd_sql:sql_query_t(
|
case ejabberd_sql:sql_query_t(
|
||||||
?SQL("select @(t)s, @(value)s, @(action)s, @(ord)d, @(match_all)b, "
|
?SQL("select @(t)s, @(value)s, @(action)s, @(ord)d, @(match_all)b, "
|
||||||
@ -429,18 +435,8 @@ set_privacy_list(ID, RItems) ->
|
|||||||
"@(match_presence_out)b from privacy_list_data "
|
"@(match_presence_out)b from privacy_list_data "
|
||||||
"where id=%(ID)d")) of
|
"where id=%(ID)d")) of
|
||||||
{selected, ExistingItems} ->
|
{selected, ExistingItems} ->
|
||||||
{ToAdd2, ToDelete2} =
|
{ToAdd2, ToDelete2} = calculate_difference(RItems, ExistingItems),
|
||||||
lists:foldr(
|
ToAdd3 = if
|
||||||
fun(Value, {ToAdd, ToDelete}) ->
|
|
||||||
case lists:splitwith(fun(E) -> E /= Value end, ToAdd) of
|
|
||||||
{_S, []} ->
|
|
||||||
{ToAdd, [Value | ToDelete]};
|
|
||||||
{Pfx, [_ | Rest]} ->
|
|
||||||
{Pfx ++ Rest, ToDelete}
|
|
||||||
end
|
|
||||||
end, {RItems, []}, ExistingItems),
|
|
||||||
ToAdd3 =
|
|
||||||
if
|
|
||||||
ToDelete2 /= [] ->
|
ToDelete2 /= [] ->
|
||||||
ejabberd_sql:sql_query_t(
|
ejabberd_sql:sql_query_t(
|
||||||
?SQL("delete from privacy_list_data where id=%(ID)d")),
|
?SQL("delete from privacy_list_data where id=%(ID)d")),
|
||||||
|
Loading…
Reference in New Issue
Block a user