Refactor set_room_last_message_time()

- Dont depend on get_jid_id(), this saves roundtrips
This commit is contained in:
Philipp Hörist 2017-08-08 17:41:38 +02:00
parent c53e2b1bb9
commit 10b0865291
1 changed files with 13 additions and 8 deletions

View File

@ -752,16 +752,21 @@ class Logger:
return self.get_last_date_that_has_logs(account, jid)
return row.time
def set_room_last_message_time(self, jid, time):
def set_room_last_message_time(self, jid, timestamp):
"""
Set last time (in seconds since EPOCH) for which we had logs for that
room in rooms_last_message_time table
Set the timestamp of the last message we received in a room.
:param jid: The jid
:param timestamp: The timestamp in epoch
"""
jid_id = self.get_jid_id(jid, 'ROOM')
# jid_id is unique in this table, create or update :
sql = 'REPLACE INTO rooms_last_message_time VALUES (%d, %d)' % \
(jid_id, time)
self.simple_commit(sql)
self.insert_jid(jid, type_=JIDConstant.ROOM_TYPE)
sql = '''REPLACE INTO rooms_last_message_time
VALUES ((SELECT jid_id FROM jids WHERE jid = ?), ?)'''
self.con.execute(sql, (jid, timestamp))
self._timeout_commit()
def save_transport_type(self, jid, type_):
"""