25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-24 17:29:28 +01:00

add nodeidx as index on pubsub_state and pubsub_item

This commit is contained in:
Christophe Romain 2011-03-18 17:36:08 +01:00
parent f9fa168d84
commit 75d2cbcb14
3 changed files with 12 additions and 8 deletions

View File

@ -97,9 +97,11 @@ init(_Host, _ServerHost, _Options) ->
pubsub_subscription:init(),
mnesia:create_table(pubsub_state,
[{disc_copies, [node()]},
{index, [nodeidx]},
{attributes, record_info(fields, pubsub_state)}]),
mnesia:create_table(pubsub_item,
[{disc_only_copies, [node()]},
{index, [nodeidx]},
{attributes, record_info(fields, pubsub_item)}]),
ItemsFields = record_info(fields, pubsub_item),
case mnesia:table_info(pubsub_item, attributes) of
@ -224,7 +226,7 @@ create_node_permission(Host, ServerHost, NodeId, _ParentNodeId, Owner, Access) -
%% @doc <p></p>
create_node(NodeIdx, Owner) ->
OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)),
set_state(#pubsub_state{stateid = {OwnerKey, NodeIdx}, affiliation = owner}),
set_state(#pubsub_state{stateid = {OwnerKey, NodeIdx}, nodeidx = NodeIdx, affiliation = owner}),
{result, {default, broadcast}}.
%% @spec (Nodes) -> {result, {default, broadcast, Reply}}
@ -507,6 +509,7 @@ publish_item(NodeIdx, Publisher, PublishModel, MaxItems, ItemId, Payload) ->
payload = Payload};
_ ->
#pubsub_item{itemid = {ItemId, NodeIdx},
nodeidx = NodeIdx,
creation = {Now, GenKey},
modification = PubId,
payload = Payload}
@ -860,8 +863,7 @@ get_nodes_helper(NodeTree,
%% ```get_states(NodeIdx) ->
%% node_default:get_states(NodeIdx).'''</p>
get_states(NodeIdx) ->
States = case catch mnesia:match_object(
#pubsub_state{stateid = {'_', NodeIdx}, _ = '_'}) of
States = case catch mnesia:index_read(pubsub_state, NodeIdx, #pubsub_state.nodeidx) of
List when is_list(List) -> List;
_ -> []
end,
@ -911,7 +913,7 @@ del_state(NodeIdx, JID) ->
%% ```get_items(NodeIdx, From) ->
%% node_default:get_items(NodeIdx, From).'''</p>
get_items(NodeIdx, _From) ->
Items = mnesia:match_object(#pubsub_item{itemid = {'_', NodeIdx}, _ = '_'}),
Items = mnesia:index_read(pubsub_item, NodeIdx, #pubsub_item.nodeidx),
{result, lists:reverse(lists:keysort(#pubsub_item.modification, Items))}.
get_items(NodeIdx, JID, AccessModel, PresenceSubscription, RosterGroup, _SubId) ->

View File

@ -146,6 +146,7 @@
-record(pubsub_state,
{
stateid,
nodeidx,
items = [],
affiliation = 'none',
subscriptions = []
@ -161,6 +162,7 @@
-record(pubsub_item,
{
itemid,
nodeidx,
creation = {'unknown','unknown'},
modification = {'unknown','unknown'},
payload = []

View File

@ -23,7 +23,7 @@ state(JID, NodeId) ->
[S] -> S;
_ -> undefined
end.
states(NodeId) -> mnesia:dirty_match_object(#pubsub_state{stateid={'_', NodeId}, _='_'}).
states(NodeId) -> mnesia:dirty_index_read(pubsub_state, NodeId, #pubsub_state.nodeidx).
stateid(S) -> element(1, S#pubsub_state.stateid).
stateids(NodeId) -> [stateid(S) || S <- states(NodeId)].
states_by_jid(JID) -> mnesia:dirty_match_object(#pubsub_state{stateid={JID, '_'}, _='_'}).
@ -33,7 +33,7 @@ item(ItemId, NodeId) ->
[I] -> I;
_ -> undefined
end.
items(NodeId) -> mnesia:dirty_match_object(#pubsub_item{itemid={'_', NodeId}, _='_'}).
items(NodeId) -> mnesia:dirty_index_read(pubsub_item, NodeIdi, #pubsub_item.nodeidx).
itemid(I) -> element(1, I#pubsub_item.itemid).
itemids(NodeId) -> [itemid(I) || I <- items(NodeId)].
items_by_id(ItemId) -> mnesia:dirty_match_object(#pubsub_item{itemid={ItemId, '_'}, _='_'}).
@ -41,10 +41,10 @@ items_by_id(ItemId) -> mnesia:dirty_match_object(#pubsub_item{itemid={ItemId, '_
affiliated(NodeId) -> [stateid(S) || S <- states(NodeId), S#pubsub_state.affiliation=/=none].
subscribed(NodeId) -> [stateid(S) || S <- states(NodeId), S#pubsub_state.subscriptions=/=[]].
%subscribed(NodeId) -> [stateid(S) || S <- states(NodeId), S#pubsub_state.subscription=/=none]. %% old record
owners(NodeId) -> [stateid(S) || S <- mnesia:dirty_match_object(#pubsub_state{stateid={'_', NodeId}, affiliation=owner, _='_'})].
owners(NodeId) -> [stateid(S) || S <- states(NodeId), S#pubsub_state.affiliation==owner].
orphan_items(NodeId) ->
itemids(NodeId) -- lists:foldl(fun(S, A) -> A++S#pubsub_state.items end, [], mnesia:dirty_match_object(#pubsub_state{stateid={'_', NodeId}, _='_'})).
itemids(NodeId) -- lists:foldl(fun(S, A) -> A++S#pubsub_state.items end, [], states(NodeId)).
newer_items(NodeId, Seconds) ->
Now = calendar:universal_time(),
Oldest = calendar:seconds_to_daystime(Seconds),