summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe Romain <christophe.romain@process-one.net>2008-12-20 00:00:24 +0000
committerChristophe Romain <christophe.romain@process-one.net>2008-12-20 00:00:24 +0000
commit4469880c2e4755b5fae22b2529530df59915f5b7 (patch)
tree3787ab36bdca7e2bbbaf23469d7b491a2a60fc59
parentCheck option of the nodetree instead of checking configuration (diff)
Fix send_last_published_item issue when running on clustered table (EJAB-793)
SVN Revision: 1740
-rw-r--r--ChangeLog5
-rw-r--r--src/mod_pubsub/mod_pubsub.erl35
2 files changed, 31 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index b8172320..b68fd6eb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2008-12-19 Christophe Romain <christophe.romain@process-one.net>
+
+ * src/mod_pubsub/mod_pubsub.erl: Fix send_last_published_item issue
+ when running on clustered table (thanks to Vincent Barat)(EJAB-793)
+
2008-12-18 Christophe Romain <christophe.romain@process-one.net>
* src/mod_pubsub/mod_pubsub.erl: Check option of the nodetree instead
diff --git a/src/mod_pubsub/mod_pubsub.erl b/src/mod_pubsub/mod_pubsub.erl
index 748355bd..f8760528 100644
--- a/src/mod_pubsub/mod_pubsub.erl
+++ b/src/mod_pubsub/mod_pubsub.erl
@@ -1757,24 +1757,41 @@ get_items(Host, Node, From) ->
%% Host = host()
%% Node = pubsubNode()
%% LJID = {U, S, []}
-%% @doc <p>Resend the items of a node to the user.</p>
-%send_all_items(Host, Node, LJID) ->
-% send_items(Host, Node, LJID, all).
-
+%% @doc <p>Resend the last item of a node to the user.</p>
send_last_item(Host, Node, LJID) ->
send_items(Host, Node, LJID, last).
-%% TODO use cache-last-item feature
+%% @spec (Host, Node, LJID) -> any()
+%% Host = host()
+%% Node = pubsubNode()
+%% LJID = {U, S, []}
+%% @doc <p>Resend the items of a node to the user.</p>
+%% @todo use cache-last-item feature
send_items(Host, Node, LJID, Number) ->
ToSend = case get_items(Host, Node, LJID) of
[] ->
[];
Items ->
case Number of
- last -> [lists:last(Items)];
- all -> Items;
- N when N > 0 -> lists:nthtail(length(Items)-N, Items);
- _ -> Items
+ last ->
+ %%% [lists:last(Items)] does not work on clustered table
+ [First|Tail] = Items,
+ [lists:foldl(
+ fun(CurItem, LastItem) ->
+ {_, {LMS, LS, LmS}} = LastItem#pubsub_item.creation,
+ {_, {CMS, CS, CmS}} = CurItem#pubsub_item.creation,
+ LTimestamp = LMS * 1000000 + LS * 1000 + LmS,
+ CTimestamp = CMS * 1000000 + CS * 1000 + CmS,
+ if
+ CTimestamp > LTimestamp -> CurItem;
+ true -> LastItem
+ end
+ end, First, Tail)];
+ N when N > 0 ->
+ %%% This case is buggy on clustered table due to lake of order
+ lists:nthtail(length(Items)-N, Items);
+ _ ->
+ Items
end
end,
ItemsEls = lists:map(