From 3c532314ecec31c0fed718dbff80d8dc417f9fd2 Mon Sep 17 00:00:00 2001 From: "Paul \"LeoNerd\" Evans" Date: Fri, 15 Aug 2014 15:44:53 +0100 Subject: [PATCH] Fix imsync's SELECT query to only find the rooms I'm actually joined in, not every room I have ever joined --- synapse/storage/roommember.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/synapse/storage/roommember.py b/synapse/storage/roommember.py index ef73be4af..c45d128f1 100644 --- a/synapse/storage/roommember.py +++ b/synapse/storage/roommember.py @@ -111,9 +111,12 @@ class RoomMemberStore(SQLBaseStore): for membership in membership_list: args.append(membership) + # sub-select finds the row ID for the most recent (i.e. current) + # state change of this user per room, then the outer select finds those query = ("SELECT room_id, membership FROM room_memberships" - + " WHERE user_id=? AND " + where_membership - + " GROUP BY room_id ORDER BY id DESC") + + " WHERE id IN (SELECT MAX(id) FROM room_memberships" + + " WHERE user_id=? GROUP BY room_id)" + + " AND " + where_membership) return self._execute( self.cursor_to_dict, query, *args )