Skip to content
Snippets Groups Projects
Commit 96707ed7 authored by Erik Johnston's avatar Erik Johnston
Browse files

Name 'user_rooms_intersect' transaction

parent 76ec154e
Branches
Tags
No related merge requests found
...@@ -239,26 +239,28 @@ class RoomMemberStore(SQLBaseStore): ...@@ -239,26 +239,28 @@ class RoomMemberStore(SQLBaseStore):
results = self._parse_events_txn(txn, rows) results = self._parse_events_txn(txn, rows)
return results return results
@defer.inlineCallbacks
def user_rooms_intersect(self, user_id_list): def user_rooms_intersect(self, user_id_list):
""" Checks whether all the users whose IDs are given in a list share a """ Checks whether all the users whose IDs are given in a list share a
room. room.
""" """
user_list_clause = " OR ".join(["m.user_id = ?"] * len(user_id_list)) def interaction(txn):
sql = ( user_list_clause = " OR ".join(["m.user_id = ?"] * len(user_id_list))
"SELECT m.room_id FROM room_memberships as m " sql = (
"INNER JOIN current_state_events as c " "SELECT m.room_id FROM room_memberships as m "
"ON m.event_id = c.event_id " "INNER JOIN current_state_events as c "
"WHERE m.membership = 'join' " "ON m.event_id = c.event_id "
"AND (%(clause)s) " "WHERE m.membership = 'join' "
# TODO(paul): We've got duplicate rows in the database somewhere "AND (%(clause)s) "
# so we have to DISTINCT m.user_id here # TODO(paul): We've got duplicate rows in the database somewhere
"GROUP BY m.room_id HAVING COUNT(DISTINCT m.user_id) = ?" # so we have to DISTINCT m.user_id here
) % {"clause": user_list_clause} "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) txn.execute(sql, args)
args.append(len(user_id_list))
rows = yield self._execute(None, sql, *args) return len(txn.fetchall()) > 0
defer.returnValue(len(rows) > 0) return self.runInteraction("user_rooms_intersect", interaction)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment