Mercurial > libervia-backend
comparison sat/memory/sqlite.py @ 2765:378188abe941
misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 11 Jan 2019 11:13:15 +0100 |
parents | 6487b8855c9a |
children | 003b8b4b56a7 |
comparison
equal
deleted
inserted
replaced
2764:92af49cde255 | 2765:378188abe941 |
---|---|
287 return self.dbpool.runQuery("SELECT (id) FROM profiles WHERE name = ?", (name, )) | 287 return self.dbpool.runQuery("SELECT (id) FROM profiles WHERE name = ?", (name, )) |
288 | 288 |
289 def setComponent(profile_id): | 289 def setComponent(profile_id): |
290 id_ = profile_id[0][0] | 290 id_ = profile_id[0][0] |
291 d_comp = self.dbpool.runQuery("INSERT INTO components(profile_id, entry_point) VALUES (?, ?)", (id_, component)) | 291 d_comp = self.dbpool.runQuery("INSERT INTO components(profile_id, entry_point) VALUES (?, ?)", (id_, component)) |
292 d_comp.addCallback(lambda dummy: profile_id) | 292 d_comp.addCallback(lambda __: profile_id) |
293 return d_comp | 293 return d_comp |
294 | 294 |
295 def profile_created(profile_id): | 295 def profile_created(profile_id): |
296 id_= profile_id[0][0] | 296 id_= profile_id[0][0] |
297 self.profiles[name] = id_ # we synchronise the cache | 297 self.profiles[name] = id_ # we synchronise the cache |
399 d.addErrback(lambda ignore: log.error(_(u"Can't set individual parameter (%(category)s/%(name)s) for [%(profile)s] in database" % {"category": category, "name": name, "profile": profile}))) | 399 d.addErrback(lambda ignore: log.error(_(u"Can't set individual parameter (%(category)s/%(name)s) for [%(profile)s] in database" % {"category": category, "name": name, "profile": profile}))) |
400 return d | 400 return d |
401 | 401 |
402 ## History | 402 ## History |
403 | 403 |
404 def _addToHistoryCb(self, dummy, data): | 404 def _addToHistoryCb(self, __, data): |
405 # Message metadata were successfuly added to history | 405 # Message metadata were successfuly added to history |
406 # now we can add message and subject | 406 # now we can add message and subject |
407 uid = data['uid'] | 407 uid = data['uid'] |
408 for key in ('message', 'subject'): | 408 for key in ('message', 'subject'): |
409 for lang, value in data[key].iteritems(): | 409 for lang, value in data[key].iteritems(): |
410 d = self.dbpool.runQuery("INSERT INTO {key}(history_uid, {key}, language) VALUES (?,?,?)".format(key=key), | 410 d = self.dbpool.runQuery("INSERT INTO {key}(history_uid, {key}, language) VALUES (?,?,?)".format(key=key), |
411 (uid, value, lang or None)) | 411 (uid, value, lang or None)) |
412 d.addErrback(lambda dummy: log.error(_(u"Can't save following {key} in history (uid: {uid}, lang:{lang}): {value}".format( | 412 d.addErrback(lambda __: log.error(_(u"Can't save following {key} in history (uid: {uid}, lang:{lang}): {value}".format( |
413 key=key, uid=uid, lang=lang, value=value)))) | 413 key=key, uid=uid, lang=lang, value=value)))) |
414 try: | 414 try: |
415 thread = data['extra']['thread'] | 415 thread = data['extra']['thread'] |
416 except KeyError: | 416 except KeyError: |
417 pass | 417 pass |
418 else: | 418 else: |
419 thread_parent = data['extra'].get('thread_parent') | 419 thread_parent = data['extra'].get('thread_parent') |
420 d = self.dbpool.runQuery("INSERT INTO thread(history_uid, thread_id, parent_id) VALUES (?,?,?)", | 420 d = self.dbpool.runQuery("INSERT INTO thread(history_uid, thread_id, parent_id) VALUES (?,?,?)", |
421 (uid, thread, thread_parent)) | 421 (uid, thread, thread_parent)) |
422 d.addErrback(lambda dummy: log.error(_(u"Can't save following thread in history (uid: {uid}): thread:{thread}), parent:{parent}".format( | 422 d.addErrback(lambda __: log.error(_(u"Can't save following thread in history (uid: {uid}): thread:{thread}), parent:{parent}".format( |
423 uid=uid, thread=thread, parent=thread_parent)))) | 423 uid=uid, thread=thread, parent=thread_parent)))) |
424 | 424 |
425 def _addToHistoryEb(self, failure_, data): | 425 def _addToHistoryEb(self, failure_, data): |
426 failure_.trap(sqlite3.IntegrityError) | 426 failure_.trap(sqlite3.IntegrityError) |
427 sqlite_msg = failure_.value.args[0] | 427 sqlite_msg = failure_.value.args[0] |
1360 # we need to fix duplicate timestamp, as it can result in conflicts with the new schema | 1360 # we need to fix duplicate timestamp, as it can result in conflicts with the new schema |
1361 rows = yield self.dbpool.runQuery("SELECT timestamp, COUNT(*) as c FROM history GROUP BY timestamp HAVING c>1") | 1361 rows = yield self.dbpool.runQuery("SELECT timestamp, COUNT(*) as c FROM history GROUP BY timestamp HAVING c>1") |
1362 if rows: | 1362 if rows: |
1363 log.info("fixing duplicate timestamp") | 1363 log.info("fixing duplicate timestamp") |
1364 fixed = [] | 1364 fixed = [] |
1365 for timestamp, dummy in rows: | 1365 for timestamp, __ in rows: |
1366 ids_rows = yield self.dbpool.runQuery("SELECT id from history where timestamp=?", (timestamp,)) | 1366 ids_rows = yield self.dbpool.runQuery("SELECT id from history where timestamp=?", (timestamp,)) |
1367 for idx, (id_,) in enumerate(ids_rows): | 1367 for idx, (id_,) in enumerate(ids_rows): |
1368 fixed.append(id_) | 1368 fixed.append(id_) |
1369 yield self.dbpool.runQuery("UPDATE history SET timestamp=? WHERE id=?", (float(timestamp) + idx * 0.001, id_)) | 1369 yield self.dbpool.runQuery("UPDATE history SET timestamp=? WHERE id=?", (float(timestamp) + idx * 0.001, id_)) |
1370 log.info(u"fixed messages with ids {}".format(u', '.join([unicode(id_) for id_ in fixed]))) | 1370 log.info(u"fixed messages with ids {}".format(u', '.join([unicode(id_) for id_ in fixed]))) |
1484 d = self.dbpool.runQuery("SELECT id FROM profiles WHERE id=?", (profile_id,)) | 1484 d = self.dbpool.runQuery("SELECT id FROM profiles WHERE id=?", (profile_id,)) |
1485 d.addCallback(prepare_queries, xmpp_password) | 1485 d.addCallback(prepare_queries, xmpp_password) |
1486 list_.append(d) | 1486 list_.append(d) |
1487 | 1487 |
1488 d_list = defer.DeferredList(list_) | 1488 d_list = defer.DeferredList(list_) |
1489 d_list.addCallback(lambda dummy: ret) | 1489 d_list.addCallback(lambda __: ret) |
1490 return d_list | 1490 return d_list |
1491 | 1491 |
1492 def updateLiberviaConf(values): | 1492 def updateLiberviaConf(values): |
1493 try: | 1493 try: |
1494 profile_id = values[0][0] | 1494 profile_id = values[0][0] |
1505 d = self.dbpool.runQuery("SELECT value FROM param_ind WHERE category=? AND name=? AND profile_id=?", xmpp_pass_path + (profile_id,)) | 1505 d = self.dbpool.runQuery("SELECT value FROM param_ind WHERE category=? AND name=? AND profile_id=?", xmpp_pass_path + (profile_id,)) |
1506 return d.addCallback(cb) | 1506 return d.addCallback(cb) |
1507 | 1507 |
1508 d = self.dbpool.runQuery("SELECT id FROM profiles WHERE name='libervia'") | 1508 d = self.dbpool.runQuery("SELECT id FROM profiles WHERE name='libervia'") |
1509 d.addCallback(updateLiberviaConf) | 1509 d.addCallback(updateLiberviaConf) |
1510 d.addCallback(lambda dummy: self.dbpool.runQuery("SELECT profile_id,value FROM param_ind WHERE category=? AND name=?", xmpp_pass_path)) | 1510 d.addCallback(lambda __: self.dbpool.runQuery("SELECT profile_id,value FROM param_ind WHERE category=? AND name=?", xmpp_pass_path)) |
1511 d.addCallback(encrypt_values) | 1511 d.addCallback(encrypt_values) |
1512 return d | 1512 return d |