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

Logger: Preload DiscoInfo

There are times for example when we open the StartChat Dialog, where
we need potentially hundreads of DiscoInfo entrys instantly.

If we execute a database query for each one of them this becomes a
parent 9a8ca991
Pipeline #4936 passed with stages
in 3 minutes and 32 seconds
......@@ -234,6 +234,7 @@ class Logger:
def _create_databases(self):
if os.path.isdir(self._log_db_path):
......@@ -1670,6 +1671,17 @@ class Logger:'Set message archive info: %s %s', jid, kwargs)
def _fill_disco_info_cache(self):
sql = '''SELECT disco_info as "disco_info [disco_info]",
jid, last_seen FROM
rows = self._con.execute(sql).fetchall()
for row in rows:
disco_info = row.disco_info._replace(timestamp=row.last_seen)
self._disco_info_cache[row.jid] = disco_info'%s DiscoInfo entrys loaded', len(rows))
def get_last_disco_info(self, jid, max_age=0):
......@@ -1681,28 +1693,11 @@ class Logger:
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:
max_timestamp = time.time() - max_age if max_age else 0
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
WHERE jid = ?'''
row = self._con.execute(sql, (str(jid),)).fetchone()
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
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