synapse/storage/user_directory.py
def add_profiles_to_user_dir(self, room_id, users_with_profile):
        """Add profiles to the user directory

        Args:
            room_id (str): A room_id that all users are joined to
            users_with_profile (dict): Users to add to directory in the form of
                mapping of user_id -> ProfileInfo
        """
        if isinstance(self.database_engine, PostgresEngine):
            # We weight the loclpart most highly, then display name and finally
            # server name
            sql = """
                INSERT INTO user_directory_search(user_id, vector)
                VALUES (?,
                    setweight(to_tsvector('english', ?), 'A')
                    || setweight(to_tsvector('english', ?), 'D')
                    || setweight(to_tsvector('english', COALESCE(?, '')), 'B')
                )
            """
            args = (
                (
                    user_id, get_localpart_from_id(user_id), get_domain_from_id(user_id),
                    profile.display_name,
                )
                for user_id, profile in users_with_profile.iteritems()
            )
        elif isinstance(self.database_engine, Sqlite3Engine):
            sql = """
                INSERT INTO user_directory_search(user_id, value)
                VALUES (?,?)
            """
            args = (
                (
                    user_id,
                    "%s %s" % (user_id, p.display_name,) if p.display_name else user_id
                )
                for user_id, p in users_with_profile.iteritems()
            )
        else:
            # This should be unreachable.
            raise Exception("Unrecognized database engine")

        def _add_profiles_to_user_dir_txn(txn):
            txn.executemany(sql, args)
            self._simple_insert_many_txn(
                txn,
                table="user_directory",
                values=[
                    {
                        "user_id": user_id,
                        "room_id": room_id,
                        "display_name": profile.display_name,
                        "avatar_url": profile.avatar_url,
                    }
                    for user_id, profile in users_with_profile.iteritems()
                ]
            )
            for user_id in users_with_profile:
                txn.call_after(
                    self.get_user_in_directory.invalidate, (user_id,)
                )

        return self.runInteraction(
            "add_profiles_to_user_dir", _add_profiles_to_user_dir_txn
        )
Add profiles to the user directory

        Args:
            room_id (str): A room_id that all users are joined to
            users_with_profile (dict): Users to add to directory in the form of
                mapping of user_id -> ProfileInfo
        
Add profiles to the user directory
Add profiles to the user directory
def add_profiles_to_user_dir(self, room_id, users_with_profile):
        if isinstance(self.database_engine, PostgresEngine):
            sql = """
                INSERT INTO user_directory_search(user_id, vector)
                VALUES (?,
                    setweight(to_tsvector('english', ?), 'A')
                    || setweight(to_tsvector('english', ?), 'D')
                    || setweight(to_tsvector('english', COALESCE(?, '')), 'B')
                )
            """
            args = (
                (
                    user_id, get_localpart_from_id(user_id), get_domain_from_id(user_id),
                    profile.display_name,
                )
                for user_id, profile in users_with_profile.iteritems()
            )
        elif isinstance(self.database_engine, Sqlite3Engine):
            sql = """
                INSERT INTO user_directory_search(user_id, value)
                VALUES (?,?)
            """
            args = (
                (
                    user_id,
                    "%s %s" % (user_id, p.display_name,) if p.display_name else user_id
                )
                for user_id, p in users_with_profile.iteritems()
            )
        else:
            raise Exception("Unrecognized database engine")
        def _add_profiles_to_user_dir_txn(txn):
            txn.executemany(sql, args)
            self._simple_insert_many_txn(
                txn,
                table="user_directory",
                values=[
                    {
                        "user_id": user_id,
                        "room_id": room_id,
                        "display_name": profile.display_name,
                        "avatar_url": profile.avatar_url,
                    }
                    for user_id, profile in users_with_profile.iteritems()
                ]
            )
            for user_id in users_with_profile:
                txn.call_after(
                    self.get_user_in_directory.invalidate, (user_id,)
                )
        return self.runInteraction(
            "add_profiles_to_user_dir", _add_profiles_to_user_dir_txn
        )
def add_profiles_to_user_dir ( self , room_id , users_with_profile ) : if isinstance ( self . database_engine , PostgresEngine ) : sql = """
                INSERT INTO user_directory_search(user_id, vector)
                VALUES (?,
                    setweight(to_tsvector('english', ?), 'A')
                    || setweight(to_tsvector('english', ?), 'D')
                    || setweight(to_tsvector('english', COALESCE(?, '')), 'B')
                )
            """ args = ( ( user_id , get_localpart_from_id ( user_id ) , get_domain_from_id ( user_id ) , profile . display_name , ) for user_id , profile in users_with_profile . iteritems ( ) ) elif isinstance ( self . database_engine , Sqlite3Engine ) : sql = """
                INSERT INTO user_directory_search(user_id, value)
                VALUES (?,?)
            """ args = ( ( user_id , "%s %s" % ( user_id , p . display_name , ) if p . display_name else user_id ) for user_id , p in users_with_profile . iteritems ( ) ) else : raise Exception ( "Unrecognized database engine" ) def _add_profiles_to_user_dir_txn ( txn ) : txn . executemany ( sql , args ) self . _simple_insert_many_txn ( txn , table = "user_directory" , values = [ { "user_id" : user_id , "room_id" : room_id , "display_name" : profile . display_name , "avatar_url" : profile . avatar_url , } for user_id , profile in users_with_profile . iteritems ( ) ] ) for user_id in users_with_profile : txn . call_after ( self . get_user_in_directory . invalidate , ( user_id , ) ) return self . runInteraction ( "add_profiles_to_user_dir" , _add_profiles_to_user_dir_txn )
Add profiles to the user directory
Add profiles to the user directory
"""Add profiles to the user directory

        Args:
            room_id (str): A room_id that all users are joined to
            users_with_profile (dict): Users to add to directory in the form of
                mapping of user_id -> ProfileInfo
        """ # We weight the loclpart most highly, then display name and finally # server name # This should be unreachable.
self
room_id
A room_id that all users are joined to
A room_id that all users are joined to
users_with_profile
Users to add to directory in the form of
mapping of user_id -> ProfileInfo
Users to add to directory in the form of mapping of user_id - > ProfileInfo