comparison src/memory/sqlite.py @ 1221:5e5661ab5c81

memory: getHistory with limit=0 now returns an empty list, use limit=None to return all messages
author souliane <souliane@mailoo.org>
date Fri, 03 Oct 2014 12:43:59 +0200
parents 1baa116501fa
children e6e0ea4dc835
comparison
equal deleted inserted replaced
1220:f91e7028e2c3 1221:5e5661ab5c81
262 message, _type, extra_, self.profiles[profile])) 262 message, _type, extra_, self.profiles[profile]))
263 d.addErrback(lambda ignore: log.error(_("Can't save following message in history: from [%(from_jid)s] to [%(to_jid)s] ==> [%(message)s]" % 263 d.addErrback(lambda ignore: log.error(_("Can't save following message in history: from [%(from_jid)s] to [%(to_jid)s] ==> [%(message)s]" %
264 {"from_jid": from_jid.full(), "to_jid": to_jid.full(), "message": message}))) 264 {"from_jid": from_jid.full(), "to_jid": to_jid.full(), "message": message})))
265 return d 265 return d
266 266
267 def getHistory(self, from_jid, to_jid, limit=0, between=True, profile=None): 267 def getHistory(self, from_jid, to_jid, limit=None, between=True, profile=None):
268 """Store a new message in history 268 """Store a new message in history
269 @param from_jid: source JID (full, or bare for catchall 269 @param from_jid: source JID (full, or bare for catchall
270 @param to_jid: dest JID (full, or bare for catchall 270 @param to_jid: dest JID (full, or bare for catchall
271 @param size: maximum number of messages to get, or 0 for unlimited 271 @param size: maximum number of messages to get, or None for unlimited
272 """ 272 """
273 assert(profile) 273 assert(profile)
274 if limit == 0:
275 return defer.succeed([])
274 276
275 def sqliteToList(query_result): 277 def sqliteToList(query_result):
276 query_result.reverse() 278 query_result.reverse()
277 result = [] 279 result = []
278 for row in query_result: 280 for row in query_result:
305 query_parts.append("%s AND %s" % (test_jid('source', from_jid), 307 query_parts.append("%s AND %s" % (test_jid('source', from_jid),
306 test_jid('dest', to_jid))) 308 test_jid('dest', to_jid)))
307 309
308 query_parts.append("ORDER BY timestamp DESC") 310 query_parts.append("ORDER BY timestamp DESC")
309 311
310 if limit: 312 if limit is not None:
311 query_parts.append("LIMIT ?") 313 query_parts.append("LIMIT ?")
312 values.append(limit) 314 values.append(limit)
313 315
314 d = self.dbpool.runQuery(" ".join(query_parts), values) 316 d = self.dbpool.runQuery(" ".join(query_parts), values)
315 return d.addCallback(sqliteToList) 317 return d.addCallback(sqliteToList)