Add an option to disable search for homeservers which may not be interested in it (#4230)
This is useful for homeservers not intended for users, such as bot-only homeservers or ones that only process IoT data.
This commit is contained in:
parent
512e94d230
commit
158ffb92f1
|
@ -0,0 +1 @@
|
||||||
|
Add an option to disable search for homeservers that may not be interested in it.
|
|
@ -62,6 +62,11 @@ class ServerConfig(Config):
|
||||||
# master, potentially causing inconsistency.
|
# master, potentially causing inconsistency.
|
||||||
self.enable_media_repo = config.get("enable_media_repo", True)
|
self.enable_media_repo = config.get("enable_media_repo", True)
|
||||||
|
|
||||||
|
# whether to enable search. If disabled, new entries will not be inserted
|
||||||
|
# into the search tables and they will not be indexed. Users will receive
|
||||||
|
# errors when attempting to search for messages.
|
||||||
|
self.enable_search = config.get("enable_search", True)
|
||||||
|
|
||||||
self.filter_timeline_limit = config.get("filter_timeline_limit", -1)
|
self.filter_timeline_limit = config.get("filter_timeline_limit", -1)
|
||||||
|
|
||||||
# Whether we should block invites sent to users on this server
|
# Whether we should block invites sent to users on this server
|
||||||
|
@ -384,7 +389,12 @@ class ServerConfig(Config):
|
||||||
# mau_limit_reserved_threepids:
|
# mau_limit_reserved_threepids:
|
||||||
# - medium: 'email'
|
# - medium: 'email'
|
||||||
# address: 'reserved_user@example.com'
|
# address: 'reserved_user@example.com'
|
||||||
|
#
|
||||||
|
# Room searching
|
||||||
|
#
|
||||||
|
# If disabled, new messages will not be indexed for searching and users
|
||||||
|
# will receive errors when searching for messages. Defaults to enabled.
|
||||||
|
# enable_search: true
|
||||||
""" % locals()
|
""" % locals()
|
||||||
|
|
||||||
def read_arguments(self, args):
|
def read_arguments(self, args):
|
||||||
|
|
|
@ -50,6 +50,9 @@ class SearchHandler(BaseHandler):
|
||||||
dict to be returned to the client with results of search
|
dict to be returned to the client with results of search
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if not self.hs.config.enable_search:
|
||||||
|
raise SynapseError(400, "Search is disabled on this homeserver")
|
||||||
|
|
||||||
batch_group = None
|
batch_group = None
|
||||||
batch_group_key = None
|
batch_group_key = None
|
||||||
batch_token = None
|
batch_token = None
|
||||||
|
|
|
@ -45,6 +45,10 @@ class SearchStore(BackgroundUpdateStore):
|
||||||
|
|
||||||
def __init__(self, db_conn, hs):
|
def __init__(self, db_conn, hs):
|
||||||
super(SearchStore, self).__init__(db_conn, hs)
|
super(SearchStore, self).__init__(db_conn, hs)
|
||||||
|
|
||||||
|
if not hs.config.enable_search:
|
||||||
|
return
|
||||||
|
|
||||||
self.register_background_update_handler(
|
self.register_background_update_handler(
|
||||||
self.EVENT_SEARCH_UPDATE_NAME, self._background_reindex_search
|
self.EVENT_SEARCH_UPDATE_NAME, self._background_reindex_search
|
||||||
)
|
)
|
||||||
|
@ -316,6 +320,8 @@ class SearchStore(BackgroundUpdateStore):
|
||||||
entries (iterable[SearchEntry]):
|
entries (iterable[SearchEntry]):
|
||||||
entries to be added to the table
|
entries to be added to the table
|
||||||
"""
|
"""
|
||||||
|
if not self.hs.config.enable_search:
|
||||||
|
return
|
||||||
if isinstance(self.database_engine, PostgresEngine):
|
if isinstance(self.database_engine, PostgresEngine):
|
||||||
sql = (
|
sql = (
|
||||||
"INSERT INTO event_search"
|
"INSERT INTO event_search"
|
||||||
|
|
Loading…
Reference in New Issue