synapse/storage/search.py
def store_search_entries_txn(self, txn, entries):
        """Add entries to the search table

        Args:
            txn (cursor):
            entries (iterable[SearchEntry]):
                entries to be added to the table
        """
        if isinstance(self.database_engine, PostgresEngine):
            sql = (
                "INSERT INTO event_search"
                " (event_id, room_id, key, vector, stream_ordering, origin_server_ts)"
                " VALUES (?,?,?,to_tsvector('english', ?),?,?)"
            )

            args = ((
                entry.event_id, entry.room_id, entry.key, entry.value,
                entry.stream_ordering, entry.origin_server_ts,
            ) for entry in entries)

            # inserts to a GIN index are normally batched up into a pending
            # list, and then all committed together once the list gets to a
            # certain size. The trouble with that is that postgres (pre-9.5)
            # uses work_mem to determine the length of the list, and work_mem
            # is typically very large.
            #
            # We therefore reduce work_mem while we do the insert.
            #
            # (postgres 9.5 uses the separate gin_pending_list_limit setting,
            # so doesn't suffer the same problem, but changing work_mem will
            # be harmless)
            #
            # Note that we don't need to worry about restoring it on
            # exception, because exceptions will cause the transaction to be
            # rolled back, including the effects of the SET command.
            #
            # Also: we use SET rather than SET LOCAL because there's lots of
            # other stuff going on in this transaction, which want to have the
            # normal work_mem setting.

            txn.execute("SET work_mem='256kB'")
            txn.executemany(sql, args)
            txn.execute("RESET work_mem")

        elif isinstance(self.database_engine, Sqlite3Engine):
            sql = (
                "INSERT INTO event_search (event_id, room_id, key, value)"
                " VALUES (?,?,?,?)"
            )
            args = ((
                entry.event_id, entry.room_id, entry.key, entry.value,
            ) for entry in entries)

            txn.executemany(sql, args)
        else:
            # This should be unreachable.
            raise Exception("Unrecognized database engine")
Add entries to the search table

        Args:
            txn (cursor):
            entries (iterable[SearchEntry]):
                entries to be added to the table
        
Add entries to the search table
Add entries to the search table
def store_search_entries_txn(self, txn, entries):
        if isinstance(self.database_engine, PostgresEngine):
            sql = (
                "INSERT INTO event_search"
                " (event_id, room_id, key, vector, stream_ordering, origin_server_ts)"
                " VALUES (?,?,?,to_tsvector('english', ?),?,?)"
            )
            args = ((
                entry.event_id, entry.room_id, entry.key, entry.value,
                entry.stream_ordering, entry.origin_server_ts,
            ) for entry in entries)
             We therefore reduce work_mem while we do the insert.
             (postgres 9.5 uses the separate gin_pending_list_limit setting,
             so doesn't suffer the same problem, but changing work_mem will
             be harmless)
             Note that we don't need to worry about restoring it on
             exception, because exceptions will cause the transaction to be
             rolled back, including the effects of the SET command.
             Also: we use SET rather than SET LOCAL because there's lots of
             other stuff going on in this transaction, which want to have the
             normal work_mem setting.
            txn.execute("SET work_mem='256kB'")
            txn.executemany(sql, args)
            txn.execute("RESET work_mem")
        elif isinstance(self.database_engine, Sqlite3Engine):
            sql = (
                "INSERT INTO event_search (event_id, room_id, key, value)"
                " VALUES (?,?,?,?)"
            )
            args = ((
                entry.event_id, entry.room_id, entry.key, entry.value,
            ) for entry in entries)
            txn.executemany(sql, args)
        else:
             This should be unreachable.
            raise Exception("Unrecognized database engine")
def store_search_entries_txn ( self , txn , entries ) : if isinstance ( self . database_engine , PostgresEngine ) : sql = ( "INSERT INTO event_search" " (event_id, room_id, key, vector, stream_ordering, origin_server_ts)" " VALUES (?,?,?,to_tsvector('english', ?),?,?)" ) args = ( ( entry . event_id , entry . room_id , entry . key , entry . value , entry . stream_ordering , entry . origin_server_ts , ) for entry in entries ) txn . execute ( "SET work_mem='256kB'" ) txn . executemany ( sql , args ) txn . execute ( "RESET work_mem" ) elif isinstance ( self . database_engine , Sqlite3Engine ) : sql = ( "INSERT INTO event_search (event_id, room_id, key, value)" " VALUES (?,?,?,?)" ) args = ( ( entry . event_id , entry . room_id , entry . key , entry . value , ) for entry in entries ) txn . executemany ( sql , args ) else : raise Exception ( "Unrecognized database engine" )
Add entries to the search table
Add entries to the search table
"""Add entries to the search table

        Args:
            txn (cursor):
            entries (iterable[SearchEntry]):
                entries to be added to the table
        """ # inserts to a GIN index are normally batched up into a pending # list, and then all committed together once the list gets to a # certain size. The trouble with that is that postgres (pre-9.5) # uses work_mem to determine the length of the list, and work_mem # is typically very large. # # We therefore reduce work_mem while we do the insert. # # (postgres 9.5 uses the separate gin_pending_list_limit setting, # so doesn't suffer the same problem, but changing work_mem will # be harmless) # # Note that we don't need to worry about restoring it on # exception, because exceptions will cause the transaction to be # rolled back, including the effects of the SET command. # # Also: we use SET rather than SET LOCAL because there's lots of # other stuff going on in this transaction, which want to have the # normal work_mem setting. # This should be unreachable.
self
txn
None
entries
entries to be added to the table
entries to be added to the table