Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit eb17de1

Browse files
committed
Fix get_moderators query
1 parent 178ddd6 commit eb17de1

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

api/ws.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ def get_moderators(self, message_id):
8989

9090
def parse_response(moderators):
9191
if moderators is not None:
92-
self.factory.db.moderators.clear_all()
92+
current_mods = self.factory.db.settings.get()[11]
93+
self.factory.db.moderators.clear_all(except_guids=current_mods)
9394

9495
def parse_profile(profile, node):
9596
if profile is not None:

db/datastore.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,12 +852,24 @@ def delete_moderator(self, guid):
852852
conn.commit()
853853
conn.close()
854854

855-
def clear_all(self):
855+
def clear_all(self, except_guids=None):
856+
mods = []
857+
if except_guids is not None:
858+
for guid in except_guids:
859+
info = self.get_moderator(guid)
860+
mods.append(info)
856861
conn = Database.connect_database(self.PATH)
857862
with conn:
858863
cursor = conn.cursor()
859864
cursor.execute('''DELETE FROM moderators''')
860865
conn.commit()
866+
for mod in mods:
867+
if mod is not None:
868+
cursor.execute('''INSERT OR REPLACE INTO moderators(guid, pubkey, bitcoinKey,
869+
bitcoinSignature, handle, name, description, avatar, fee)
870+
VALUES (?,?,?,?,?,?,?,?,?)''', (mod[0], mod[1], mod[2], mod[3], mod[4],
871+
mod[5], mod[6], mod[7], mod[8]))
872+
861873
conn.close()
862874

863875

0 commit comments

Comments
 (0)