feature: add a mam_sync_limit tab option
This commit is contained in:
parent
4ae1b714c4
commit
18b1d5ae72
5 changed files with 17 additions and 5 deletions
|
@ -868,6 +868,14 @@ Options related to logging.
|
|||
If ``true``, will try to fill local logs with missing MAM history
|
||||
when opening a tab or joining a room.
|
||||
|
||||
mam_sync_limit
|
||||
|
||||
**Default value:** ``2000``
|
||||
|
||||
Maximum number of messages to fetch on a MAM sync. Will affect
|
||||
performance when joining rooms with a huge backlog for the first time
|
||||
or after a long period.
|
||||
|
||||
Plugins
|
||||
~~~~~~~
|
||||
|
||||
|
|
|
@ -93,6 +93,7 @@ DEFAULT_CONFIG: ConfigDict = {
|
|||
'log_dir': '',
|
||||
'log_errors': True,
|
||||
'mam_sync': True,
|
||||
'mam_sync_limit': 2000,
|
||||
'max_lines_in_memory': 2048,
|
||||
'max_messages_in_memory': 2048,
|
||||
'max_nick_length': 25,
|
||||
|
|
|
@ -265,14 +265,15 @@ class MAMFiller:
|
|||
logger: Logger
|
||||
future: asyncio.Future
|
||||
done: asyncio.Event
|
||||
max_msgs: int = 2000
|
||||
limit: int
|
||||
|
||||
def __init__(self, logger: Logger, tab: tabs.ChatTab):
|
||||
def __init__(self, logger: Logger, tab: tabs.ChatTab, limit: int = 2000):
|
||||
self.tab = tab
|
||||
self.logger = logger
|
||||
logger.fd_busy(tab.jid)
|
||||
self.future = asyncio.ensure_future(self.fetch_routine())
|
||||
self.done = asyncio.Event()
|
||||
self.limit = limit
|
||||
|
||||
def cancel(self) -> None:
|
||||
"""Cancel the routine and signal the end."""
|
||||
|
@ -292,7 +293,7 @@ class MAMFiller:
|
|||
messages = await fetch_history(
|
||||
self.tab,
|
||||
start=last_msg_time,
|
||||
amount=self.max_msgs,
|
||||
amount=self.limit,
|
||||
)
|
||||
log.debug(
|
||||
'Fetched %s messages to fill local logs for %s',
|
||||
|
|
|
@ -1014,7 +1014,8 @@ class OneToOneTab(ChatTab):
|
|||
use_log = config.get_by_tabname('use_log', self.jid)
|
||||
mam_sync = config.get_by_tabname('mam_sync', self.jid)
|
||||
if use_log and mam_sync:
|
||||
self.mam_filler = MAMFiller(logger, self)
|
||||
limit = config.get_by_tabname('mam_sync_limit', self.jid)
|
||||
self.mam_filler = MAMFiller(logger, self, limit)
|
||||
asyncio.ensure_future(
|
||||
LogLoader(logger, self, use_log).tab_open()
|
||||
)
|
||||
|
|
|
@ -181,7 +181,8 @@ class MucTab(ChatTab):
|
|||
use_log = config.get_by_tabname('mam_sync', self.general_jid)
|
||||
mam_sync = config.get_by_tabname('mam_sync', self.general_jid)
|
||||
if self.mam_filler is None and use_log and mam_sync:
|
||||
self.mam_filler = MAMFiller(logger, self)
|
||||
limit = config.get_by_tabname('mam_sync_limit', self.jid)
|
||||
self.mam_filler = MAMFiller(logger, self, limit)
|
||||
muc.join_groupchat(
|
||||
self.core,
|
||||
self.jid.bare,
|
||||
|
|
Loading…
Reference in a new issue