diff options
author | Erik Johnston <erik@matrix.org> | 2015-01-06 14:44:27 +0000 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2015-01-06 14:44:27 +0000 |
commit | 96707ed7185fc5c1668c8a31b62c67bdf39ed777 (patch) | |
tree | 58cc0d979ff25eb85940cd1b3d8a5037de85d1b1 /synapse/storage | |
parent | We don't need the full events for get_rooms_for_user_where_membership_is (diff) | |
download | synapse-96707ed7185fc5c1668c8a31b62c67bdf39ed777.tar.xz |
Name 'user_rooms_intersect' transaction
Diffstat (limited to 'synapse/storage')
-rw-r--r-- | synapse/storage/roommember.py | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/synapse/storage/roommember.py b/synapse/storage/roommember.py index c495fab919..11f8f78773 100644 --- a/synapse/storage/roommember.py +++ b/synapse/storage/roommember.py @@ -239,26 +239,28 @@ class RoomMemberStore(SQLBaseStore): results = self._parse_events_txn(txn, rows) return results - @defer.inlineCallbacks def user_rooms_intersect(self, user_id_list): """ Checks whether all the users whose IDs are given in a list share a room. """ - user_list_clause = " OR ".join(["m.user_id = ?"] * len(user_id_list)) - sql = ( - "SELECT m.room_id FROM room_memberships as m " - "INNER JOIN current_state_events as c " - "ON m.event_id = c.event_id " - "WHERE m.membership = 'join' " - "AND (%(clause)s) " - # TODO(paul): We've got duplicate rows in the database somewhere - # so we have to DISTINCT m.user_id here - "GROUP BY m.room_id HAVING COUNT(DISTINCT m.user_id) = ?" - ) % {"clause": user_list_clause} + def interaction(txn): + user_list_clause = " OR ".join(["m.user_id = ?"] * len(user_id_list)) + sql = ( + "SELECT m.room_id FROM room_memberships as m " + "INNER JOIN current_state_events as c " + "ON m.event_id = c.event_id " + "WHERE m.membership = 'join' " + "AND (%(clause)s) " + # TODO(paul): We've got duplicate rows in the database somewhere + # so we have to DISTINCT m.user_id here + "GROUP BY m.room_id HAVING COUNT(DISTINCT m.user_id) = ?" + ) % {"clause": user_list_clause} + + args = list(user_id_list) + args.append(len(user_id_list)) - args = list(user_id_list) - args.append(len(user_id_list)) + txn.execute(sql, args) - rows = yield self._execute(None, sql, *args) + return len(txn.fetchall()) > 0 - defer.returnValue(len(rows) > 0) + return self.runInteraction("user_rooms_intersect", interaction) |