Philipp Hörist pushed to branch master at gajim / gajim
Commits:
-
73fbb582
by Philipp Hörist at 2019-08-17T18:42:42Z
-
1a5395cf
by Philipp Hörist at 2019-08-17T18:42:42Z
2 changed files:
Changes:
| ... | ... | @@ -1498,17 +1498,26 @@ class Logger: |
| 1498 | 1498 |
log.info('Set message archive info: %s %s', jid, kwargs)
|
| 1499 | 1499 |
self._timeout_commit()
|
| 1500 | 1500 |
|
| 1501 |
- def get_last_disco_info(self, jid):
|
|
| 1501 |
+ def get_last_disco_info(self, jid, max_age=0):
|
|
| 1502 | 1502 |
"""
|
| 1503 | 1503 |
Get last disco info from jid
|
| 1504 | 1504 |
|
| 1505 |
- :param jid: The jid
|
|
| 1505 |
+ :param jid: The jid
|
|
| 1506 |
+ |
|
| 1507 |
+ :param max_age: max age in seconds of the DiscoInfo record
|
|
| 1506 | 1508 |
|
| 1507 | 1509 |
"""
|
| 1508 | 1510 |
|
| 1509 |
- if jid in self._disco_info_cache:
|
|
| 1510 |
- return self._disco_info_cache[jid]
|
|
| 1511 |
+ max_timestamp = time.time() - max_age if max_age else 0
|
|
| 1512 |
+ |
|
| 1513 |
+ # Try the cache
|
|
| 1514 |
+ disco_info = self._disco_info_cache.get(jid)
|
|
| 1515 |
+ if disco_info is not None:
|
|
| 1516 |
+ if max_timestamp > disco_info.timestamp:
|
|
| 1517 |
+ return None
|
|
| 1518 |
+ return disco_info
|
|
| 1511 | 1519 |
|
| 1520 |
+ # Try the database
|
|
| 1512 | 1521 |
sql = '''SELECT disco_info as "disco_info [disco_info]", last_seen FROM
|
| 1513 | 1522 |
last_seen_disco_info
|
| 1514 | 1523 |
WHERE jid = ?'''
|
| ... | ... | @@ -1516,6 +1525,9 @@ class Logger: |
| 1516 | 1525 |
if row is None:
|
| 1517 | 1526 |
return None
|
| 1518 | 1527 |
|
| 1528 |
+ if max_timestamp > row.last_seen:
|
|
| 1529 |
+ return None
|
|
| 1530 |
+ |
|
| 1519 | 1531 |
disco_info = row.disco_info._replace(timestamp=row.last_seen)
|
| 1520 | 1532 |
self._disco_info_cache[jid] = disco_info
|
| 1521 | 1533 |
return disco_info
|
| ... | ... | @@ -141,9 +141,13 @@ class MUC(BaseModule): |
| 141 | 141 |
|
| 142 | 142 |
self._muc_data[muc_data.jid] = muc_data
|
| 143 | 143 |
|
| 144 |
- self._con.get_module('Discovery').disco_muc(
|
|
| 145 |
- muc_data.jid,
|
|
| 146 |
- callback=self._on_disco_result)
|
|
| 144 |
+ disco_info = app.logger.get_last_disco_info(muc_data.jid, max_age=60)
|
|
| 145 |
+ if disco_info is None:
|
|
| 146 |
+ self._con.get_module('Discovery').disco_muc(
|
|
| 147 |
+ muc_data.jid,
|
|
| 148 |
+ callback=self._on_disco_result)
|
|
| 149 |
+ else:
|
|
| 150 |
+ self._join(muc_data)
|
|
| 147 | 151 |
|
| 148 | 152 |
def _on_disco_result(self, result):
|
| 149 | 153 |
if is_error_result(result):
|