Commit ca1b2091 authored by Philipp Hörist's avatar Philipp Hörist

MAM: Improve MAM efficiency

This looks at all messages incoming and saves the stanza-id if there is one.
Previously this was only done for messages of type=chat, which left out muc invites
and captcha messages, leading to fetching these messages later again.
parent dce96b5f
Pipeline #4000 failed with stages
in 2 minutes and 41 seconds
......@@ -40,6 +40,9 @@ class MAM(BaseModule):
BaseModule.__init__(self, con)
self.handlers = [
StanzaHandler(name='message',
callback=self._set_message_archive_info,
priority=41),
StanzaHandler(name='message',
callback=self._mam_message_received,
priority=51),
......@@ -101,6 +104,42 @@ class MAM(BaseModule):
# A message we received
return properties.mam.id, None
def _set_message_archive_info(self, _con, _stanza, properties):
if (properties.is_mam_message or
properties.is_pubsub or
properties.is_muc_subject):
return
if properties.type.is_groupchat:
archive_jid = properties.jid.getBare()
namespace = muc_caps_cache.get_mam_namespace(archive_jid)
timestamp = properties.timestamp
if namespace is None:
# MUC History
app.logger.set_archive_infos(
archive_jid,
last_muc_timestamp=timestamp)
return
else:
archive_jid = self._con.get_own_jid().getBare()
namespace = self._con.get_module('MAM').archiving_namespace
timestamp = None
if properties.stanza_id is None or namespace != nbxmpp.NS_MAM_2:
return
if not archive_jid == properties.stanza_id.by:
return
if not self._con.get_module('MAM').is_catch_up_finished(
archive_jid):
return
app.logger.set_archive_infos(archive_jid,
last_mam_id=properties.stanza_id.id,
last_muc_timestamp=timestamp)
def _mam_message_received(self, _con, stanza, properties):
if not properties.is_mam_message:
return
......
......@@ -293,16 +293,6 @@ class Message(BaseModule):
stanza_id=event.stanza_id,
message_id=event.message_id)
if muc_caps_cache.has_mam(event.room_jid):
finished = self._con.get_module('MAM').is_catch_up_finished(
event.room_jid)
if not finished:
return
app.logger.set_archive_infos(event.room_jid,
last_mam_id=event.stanza_id,
last_muc_timestamp=event.timestamp)
def _check_for_mam_compliance(self, room_jid, stanza_id):
namespace = caps_cache.muc_caps_cache.get_mam_namespace(room_jid)
if stanza_id is None and namespace == nbxmpp.NS_MAM_2:
......
......@@ -139,12 +139,6 @@ class ChatControlSession:
stanza_id=obj.unique_id,
message_id=obj.message_id)
jid = self.conn.get_own_jid().getStripped()
if self.conn.get_module('MAM').is_catch_up_finished(jid):
app.logger.set_archive_infos(jid,
last_mam_id=obj.stanza_id,
last_muc_timestamp=obj.timestamp)
if obj.muc_pm and not obj.gc_control:
# This is a carbon of a PM from a MUC we are not currently
# joined. We log it silently without notification.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment