Philipp Hörist pushed to branch master at gajim / gajim
Commits:
73fbb582 by Philipp Hörist at 2019-08-17T18:42:42Z
Logger: Add max_age argument for get_last_disco_info()
- - - - -
1a5395cf by Philipp Hörist at 2019-08-17T18:42:42Z
MUC: Use cached disco info on join
- - - - -
2 changed files:
- gajim/common/logger.py
- gajim/common/modules/muc.py
Changes:
=====================================
gajim/common/logger.py
=====================================
@@ -1498,17 +1498,26 @@ class Logger:
log.info('Set message archive info: %s %s', jid, kwargs)
self._timeout_commit()
- def get_last_disco_info(self, jid):
+ def get_last_disco_info(self, jid, max_age=0):
"""
Get last disco info from jid
- :param jid: The jid
+ :param jid: The jid
+
+ :param max_age: max age in seconds of the DiscoInfo record
"""
- if jid in self._disco_info_cache:
- return self._disco_info_cache[jid]
+ max_timestamp = time.time() - max_age if max_age else 0
+
+ # Try the cache
+ disco_info = self._disco_info_cache.get(jid)
+ if disco_info is not None:
+ if max_timestamp > disco_info.timestamp:
+ return None
+ return disco_info
+ # Try the database
sql = '''SELECT disco_info as "disco_info [disco_info]", last_seen FROM
last_seen_disco_info
WHERE jid = ?'''
@@ -1516,6 +1525,9 @@ class Logger:
if row is None:
return None
+ if max_timestamp > row.last_seen:
+ return None
+
disco_info = row.disco_info._replace(timestamp=row.last_seen)
self._disco_info_cache[jid] = disco_info
return disco_info
=====================================
gajim/common/modules/muc.py
=====================================
@@ -141,9 +141,13 @@ class MUC(BaseModule):
self._muc_data[muc_data.jid] = muc_data
- self._con.get_module('Discovery').disco_muc(
- muc_data.jid,
- callback=self._on_disco_result)
+ disco_info = app.logger.get_last_disco_info(muc_data.jid, max_age=60)
+ if disco_info is None:
+ self._con.get_module('Discovery').disco_muc(
+ muc_data.jid,
+ callback=self._on_disco_result)
+ else:
+ self._join(muc_data)
def _on_disco_result(self, result):
if is_error_result(result):
View it on GitLab:
https://dev.gajim.org/gajim/gajim/compare/0520546c9925ba106be0fc0e00c1629ce72a64c4...1a5395cf6f71269af9c22436a67965e2ffe970ac
--
View it on GitLab:
https://dev.gajim.org/gajim/gajim/compare/0520546c9925ba106be0fc0e00c1629ce72a64c4...1a5395cf6f71269af9c22436a67965e2ffe970ac
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits