mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	slow queries: Use internal_send_stream_message().
Note that while the test mocks the actual message send, we now have a `get_stream` call in the queue worker, so we have to set up a real stream for testing (or we could have mocked that as well, but it didn't seem necessary). The setup queries add to the amount of queries reported by the test, plus the `get_stream` call. I just made the query count a digits regex, which is a little bit lame, but I don't think it's worth risking test flakes for this.
This commit is contained in:
		@@ -26,7 +26,7 @@ from zerver.lib.push_notifications import handle_push_notification, handle_remov
 | 
			
		||||
    initialize_push_notifications, clear_push_device_tokens
 | 
			
		||||
from zerver.lib.actions import do_send_confirmation_email, \
 | 
			
		||||
    do_update_user_activity, do_update_user_activity_interval, do_update_user_presence, \
 | 
			
		||||
    internal_send_message, internal_send_private_message, notify_realm_export, \
 | 
			
		||||
    internal_send_stream_message, internal_send_private_message, notify_realm_export, \
 | 
			
		||||
    render_incoming_message, do_update_embedded_data, do_mark_stream_messages_as_read
 | 
			
		||||
from zerver.lib.url_preview import preview as url_preview
 | 
			
		||||
from zerver.lib.digest import handle_digest_email
 | 
			
		||||
@@ -38,7 +38,7 @@ from zerver.lib.streams import access_stream_by_id
 | 
			
		||||
from zerver.lib.db import reset_queries
 | 
			
		||||
from zerver.context_processors import common_context
 | 
			
		||||
from zerver.lib.outgoing_webhook import do_rest_call, get_outgoing_webhook_service_handler
 | 
			
		||||
from zerver.models import get_bot_services, RealmAuditLog
 | 
			
		||||
from zerver.models import get_bot_services, get_stream, RealmAuditLog
 | 
			
		||||
from zulip_bots.lib import ExternalBotHandler, extract_query_without_mention
 | 
			
		||||
from zerver.lib.bot_lib import EmbeddedBotHandler, get_bot_handler, EmbeddedBotQuitException
 | 
			
		||||
from zerver.lib.exceptions import RateLimited
 | 
			
		||||
@@ -453,9 +453,19 @@ class SlowQueryWorker(LoopQueueProcessingWorker):
 | 
			
		||||
            for event in slow_query_events:
 | 
			
		||||
                content += "    %s\n" % (event["query"],)
 | 
			
		||||
 | 
			
		||||
            error_bot_realm = get_system_bot(settings.ERROR_BOT).realm
 | 
			
		||||
            internal_send_message(error_bot_realm, settings.ERROR_BOT,
 | 
			
		||||
                                  "stream", settings.SLOW_QUERY_LOGS_STREAM, topic, content)
 | 
			
		||||
            error_bot = get_system_bot(settings.ERROR_BOT)
 | 
			
		||||
            realm = error_bot.realm
 | 
			
		||||
            errors_stream = get_stream(
 | 
			
		||||
                settings.SLOW_QUERY_LOGS_STREAM,
 | 
			
		||||
                realm
 | 
			
		||||
            )
 | 
			
		||||
            internal_send_stream_message(
 | 
			
		||||
                realm,
 | 
			
		||||
                error_bot,
 | 
			
		||||
                errors_stream,
 | 
			
		||||
                topic,
 | 
			
		||||
                content
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
@assign_queue('digest_emails')
 | 
			
		||||
class DigestWorker(QueueProcessingWorker):  # nocoverage
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user