Comparison

plugins/mod_carbons.lua @ 10469:658b759a1f7a

mod_carbons: Improve performance by delaying creation of carbon payload If there are no other sessions which also enabled carbons then the carbons wrapper is not used and the potentially expensive clone operation was a waste of cycles.
author Kim Alvefur <zash@zash.se>
date Sat, 30 Nov 2019 19:34:40 +0100
parent 8354:b41947a0fc0c
child 10778:a62b981db0e2
comparison
equal deleted inserted replaced
10468:7341d2f4749a 10469:658b759a1f7a
72 elseif not c2s and bare_jid == orig_from and stanza:get_child("x", "http://jabber.org/protocol/muc#user") then 72 elseif not c2s and bare_jid == orig_from and stanza:get_child("x", "http://jabber.org/protocol/muc#user") then
73 module:log("debug", "MUC PM, ignoring"); 73 module:log("debug", "MUC PM, ignoring");
74 return 74 return
75 end 75 end
76 76
77 -- Create the carbon copy and wrap it as per the Stanza Forwarding XEP 77 local carbon;
78 local copy = st.clone(stanza);
79 if c2s and not orig_to then
80 stanza.attr.to = bare_from;
81 end
82 copy.attr.xmlns = "jabber:client";
83 local carbon = st.message{ from = bare_jid, type = orig_type, }
84 :tag(c2s and "sent" or "received", { xmlns = xmlns_carbons })
85 :tag("forwarded", { xmlns = xmlns_forward })
86 :add_child(copy):reset();
87
88 user_sessions = user_sessions and user_sessions.sessions; 78 user_sessions = user_sessions and user_sessions.sessions;
89 for _, session in pairs(user_sessions) do 79 for _, session in pairs(user_sessions) do
90 -- Carbons are sent to resources that have enabled it 80 -- Carbons are sent to resources that have enabled it
91 if session.want_carbons 81 if session.want_carbons
92 -- but not the resource that sent the message, or the one that it's directed to 82 -- but not the resource that sent the message, or the one that it's directed to
93 and session ~= target_session 83 and session ~= target_session
94 -- and isn't among the top resources that would receive the message per standard routing rules 84 -- and isn't among the top resources that would receive the message per standard routing rules
95 and (c2s or session.priority ~= top_priority) then 85 and (c2s or session.priority ~= top_priority) then
86 if not carbon then
87 -- Create the carbon copy and wrap it as per the Stanza Forwarding XEP
88 local copy = st.clone(stanza);
89 if c2s and not orig_to then
90 stanza.attr.to = bare_from;
91 end
92 copy.attr.xmlns = "jabber:client";
93 carbon = st.message{ from = bare_jid, type = orig_type, }
94 :tag(c2s and "sent" or "received", { xmlns = xmlns_carbons })
95 :tag("forwarded", { xmlns = xmlns_forward })
96 :add_child(copy):reset();
97
98 end
99
96 carbon.attr.to = session.full_jid; 100 carbon.attr.to = session.full_jid;
97 module:log("debug", "Sending carbon to %s", session.full_jid); 101 module:log("debug", "Sending carbon to %s", session.full_jid);
98 session.send(carbon); 102 session.send(carbon);
99 end 103 end
100 end 104 end