Philipp Hörist pushed to branch master at gajim / gajim
Commits:
76090cdf by Philipp Hörist at 2020-02-01T11:28:56+01:00
Logger: Don't time method that does not query the database
- - - - -
0d0a31a4 by Philipp Hörist at 2020-02-01T11:49:29+01:00
Logger: Preload avatar sha for MUCs
Otherwise this becomes a bottleneck if we load many MUCs, e.g. StartChat dialog
- - - - -
1 changed file:
- gajim/common/logger.py
Changes:
=====================================
gajim/common/logger.py
=====================================
@@ -229,12 +229,14 @@ class Logger:
self._cache_db_path = configpaths.get('CACHE_DB')
self._disco_info_cache = {}
+ self._muc_avatar_sha_cache = {}
self._create_databases()
self._migrate_databases()
self._connect_databases()
self._get_jid_ids_from_db()
self._fill_disco_info_cache()
+ self._fill_muc_avatar_sha_cache()
def _create_databases(self):
if os.path.isdir(self._log_db_path):
@@ -1555,6 +1557,14 @@ class Logger:
self._con.execute(sql, (state, account_id, jid_id, message_id))
self._timeout_commit()
+ @timeit
+ def _fill_muc_avatar_sha_cache(self):
+ sql = '''SELECT jid, avatar_sha FROM muc_avatars'''
+ rows = self._con.execute(sql).fetchall()
+ for row in rows:
+ self._muc_avatar_sha_cache[row.jid] = row.avatar_sha
+ log.info('%s Avatar SHA entrys loaded', len(rows))
+
@timeit
def set_avatar_sha(self, account_jid, jid, sha=None):
"""
@@ -1598,9 +1608,10 @@ class Logger:
sql = 'UPDATE muc_avatars SET avatar_sha = ? WHERE jid = ?'
self._con.execute(sql, (sha, jid))
+ self._muc_avatar_sha_cache[jid] = sha
+
self._timeout_commit()
- @timeit
def get_muc_avatar_sha(self, jid):
"""
Get the avatar sha of a MUC
@@ -1609,10 +1620,7 @@ class Logger:
"""
- sql = '''SELECT avatar_sha FROM muc_avatars WHERE jid = ?'''
- row = self._con.execute(sql, (jid,)).fetchone()
- if row is not None:
- return row.avatar_sha
+ return self._muc_avatar_sha_cache.get(jid)
@timeit
def get_archive_infos(self, jid):
@@ -1682,7 +1690,6 @@ class Logger:
self._disco_info_cache[row.jid] = disco_info
log.info('%s DiscoInfo entrys loaded', len(rows))
- @timeit
def get_last_disco_info(self, jid, max_age=0):
"""
Get last disco info from jid
View it on GitLab:
https://dev.gajim.org/gajim/gajim/compare/e0bc8c9284f441039aa7aa2b6a0849b88f871c51...0d0a31a4f13beedfae78eb27c1aaad7b9ba13c72
--
View it on GitLab:
https://dev.gajim.org/gajim/gajim/compare/e0bc8c9284f441039aa7aa2b6a0849b88f871c51...0d0a31a4f13beedfae78eb27c1aaad7b9ba13c72
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