Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
message_fetch: Use get_base_query_for_search in messages_in_narrow_backend.
Anders Kaseorg7e75166b5f06
diff --git a/zerver/views/message_fetch.py b/zerver/views/message_fetch.pyindex 6c81011dab0..928655e61b3 100644--- a/zerver/views/message_fetch.py+++ b/zerver/views/message_fetch.py@@ -8,7 +8,7 @@ from django.http import HttpRequest, HttpResponsefrom django.utils.html import escape as escape_htmlfrom django.utils.translation import gettext as _from pydantic import Json, NonNegativeInt-from sqlalchemy.sql import and_, column, join, literal, literal_column, select, table+from sqlalchemy.sql import columnfrom sqlalchemy.types import Integer, Textfrom zerver.context_processors import get_valid_realm_from_request@@ -23,6 +23,7 @@ from zerver.lib.narrow import (add_narrow_conditions,clean_narrow_for_message_fetch,fetch_messages,+ get_base_query_for_search,is_spectator_compatible,is_web_public_narrow,parse_anchor_value,@@ -347,25 +348,11 @@ def messages_in_narrow_backend(msg_ids = [message_id for message_id in msg_ids if message_id >= first_visible_message_id]# This query is limited to messages the user has access to because they# actually received them, as reflected in `zerver_usermessage`.- query = (- select(column("message_id", Integer))- .where(- and_(- column("user_profile_id", Integer) == literal(user_profile.id),- column("message_id", Integer).in_(msg_ids),- )- )- .select_from(- join(- table("zerver_usermessage"),- table("zerver_message"),- literal_column("zerver_usermessage.message_id", Integer)- == literal_column("zerver_message.id", Integer),- )- )+ query, inner_msg_id_col = get_base_query_for_search(+ user_profile.realm_id, user_profile, need_message=True, need_user_message=True)+ query = query.where(column("message_id", Integer).in_(msg_ids))- inner_msg_id_col = column("message_id", Integer)updated_narrow = update_narrow_terms_containing_empty_topic_fallback_name(narrow)query, is_search = add_narrow_conditions(user_profile=user_profile,