mirror of https://github.com/zulip/zulip.git
tornado: Split get_events_backend into two functions.
The lower-layer function, now called get_events_backend, is intended to be called by multiple code paths (including the upcoming get_events_internal).
This commit is contained in:
parent
8aabce5a5f
commit
07af59d4cc
|
@ -50,7 +50,7 @@ def report(state, short_msg, too_old=None):
|
|||
|
||||
now = timezone_now()
|
||||
|
||||
all_users = UserActivity.objects.filter(query__in=["get_events_backend", "/api/v1/events"],
|
||||
all_users = UserActivity.objects.filter(query__in=["get_events", "/api/v1/events"],
|
||||
client__name="zephyr_mirror")
|
||||
new_inactive_users = [user for user in all_users if user.last_visit <
|
||||
now - datetime.timedelta(minutes=10)]
|
||||
|
|
|
@ -12,7 +12,7 @@ from zerver.models import Recipient, Subscription, UserProfile, get_stream
|
|||
from zerver.tornado.event_queue import maybe_enqueue_notifications, \
|
||||
allocate_client_descriptor, process_message_event, clear_client_event_queues_for_testing, \
|
||||
get_client_descriptor, missedmessage_hook
|
||||
from zerver.tornado.views import get_events_backend
|
||||
from zerver.tornado.views import get_events
|
||||
|
||||
class MissedMessageNotificationsTest(ZulipTestCase):
|
||||
"""Tests the logic for when missed-message notifications
|
||||
|
@ -175,7 +175,7 @@ class MissedMessageNotificationsTest(ZulipTestCase):
|
|||
email = user_profile.email
|
||||
self.login(email)
|
||||
|
||||
result = self.tornado_call(get_events_backend, user_profile,
|
||||
result = self.tornado_call(get_events, user_profile,
|
||||
{"apply_markdown": ujson.dumps(True),
|
||||
"client_gravatar": ujson.dumps(True),
|
||||
"event_types": ujson.dumps(["message"]),
|
||||
|
|
|
@ -129,7 +129,7 @@ from zerver.tornado.event_queue import (
|
|||
process_message_event,
|
||||
EventQueue,
|
||||
)
|
||||
from zerver.tornado.views import get_events_backend
|
||||
from zerver.tornado.views import get_events
|
||||
|
||||
from collections import OrderedDict
|
||||
import mock
|
||||
|
@ -277,7 +277,7 @@ class GetEventsTest(ZulipTestCase):
|
|||
recipient_email = recipient_user_profile.email
|
||||
self.login(email)
|
||||
|
||||
result = self.tornado_call(get_events_backend, user_profile,
|
||||
result = self.tornado_call(get_events, user_profile,
|
||||
{"apply_markdown": ujson.dumps(True),
|
||||
"client_gravatar": ujson.dumps(True),
|
||||
"event_types": ujson.dumps(["message"]),
|
||||
|
@ -287,7 +287,7 @@ class GetEventsTest(ZulipTestCase):
|
|||
self.assert_json_success(result)
|
||||
queue_id = ujson.loads(result.content)["queue_id"]
|
||||
|
||||
recipient_result = self.tornado_call(get_events_backend, recipient_user_profile,
|
||||
recipient_result = self.tornado_call(get_events, recipient_user_profile,
|
||||
{"apply_markdown": ujson.dumps(True),
|
||||
"client_gravatar": ujson.dumps(True),
|
||||
"event_types": ujson.dumps(["message"]),
|
||||
|
@ -297,7 +297,7 @@ class GetEventsTest(ZulipTestCase):
|
|||
self.assert_json_success(recipient_result)
|
||||
recipient_queue_id = ujson.loads(recipient_result.content)["queue_id"]
|
||||
|
||||
result = self.tornado_call(get_events_backend, user_profile,
|
||||
result = self.tornado_call(get_events, user_profile,
|
||||
{"queue_id": queue_id,
|
||||
"user_client": "website",
|
||||
"last_event_id": -1,
|
||||
|
@ -319,7 +319,7 @@ class GetEventsTest(ZulipTestCase):
|
|||
sender_queue_id=queue_id,
|
||||
)
|
||||
|
||||
result = self.tornado_call(get_events_backend, user_profile,
|
||||
result = self.tornado_call(get_events, user_profile,
|
||||
{"queue_id": queue_id,
|
||||
"user_client": "website",
|
||||
"last_event_id": -1,
|
||||
|
@ -348,7 +348,7 @@ class GetEventsTest(ZulipTestCase):
|
|||
sender_queue_id=queue_id,
|
||||
)
|
||||
|
||||
result = self.tornado_call(get_events_backend, user_profile,
|
||||
result = self.tornado_call(get_events, user_profile,
|
||||
{"queue_id": queue_id,
|
||||
"user_client": "website",
|
||||
"last_event_id": last_event_id,
|
||||
|
@ -363,7 +363,7 @@ class GetEventsTest(ZulipTestCase):
|
|||
|
||||
# Test that the received message in the receiver's event queue
|
||||
# exists and does not contain a local id
|
||||
recipient_result = self.tornado_call(get_events_backend, recipient_user_profile,
|
||||
recipient_result = self.tornado_call(get_events, recipient_user_profile,
|
||||
{"queue_id": recipient_queue_id,
|
||||
"user_client": "website",
|
||||
"last_event_id": -1,
|
||||
|
@ -386,7 +386,7 @@ class GetEventsTest(ZulipTestCase):
|
|||
|
||||
def get_message(apply_markdown: bool, client_gravatar: bool) -> Dict[str, Any]:
|
||||
result = self.tornado_call(
|
||||
get_events_backend,
|
||||
get_events,
|
||||
user_profile,
|
||||
dict(
|
||||
apply_markdown=ujson.dumps(apply_markdown),
|
||||
|
@ -401,7 +401,7 @@ class GetEventsTest(ZulipTestCase):
|
|||
self.assert_json_success(result)
|
||||
queue_id = ujson.loads(result.content)["queue_id"]
|
||||
|
||||
result = self.tornado_call(get_events_backend, user_profile,
|
||||
result = self.tornado_call(get_events, user_profile,
|
||||
{"queue_id": queue_id,
|
||||
"user_client": "website",
|
||||
"last_event_id": -1,
|
||||
|
@ -414,7 +414,7 @@ class GetEventsTest(ZulipTestCase):
|
|||
self.send_personal_message(email, self.example_email("othello"), "hello")
|
||||
self.send_stream_message(email, "Denmark", "**hello**")
|
||||
|
||||
result = self.tornado_call(get_events_backend, user_profile,
|
||||
result = self.tornado_call(get_events, user_profile,
|
||||
{"queue_id": queue_id,
|
||||
"user_client": "website",
|
||||
"last_event_id": -1,
|
||||
|
|
|
@ -316,7 +316,7 @@ class UserPresenceTests(ZulipTestCase):
|
|||
UserActivity.objects.get_or_create(
|
||||
user_profile=user_profile,
|
||||
client=client,
|
||||
query='get_events_backend',
|
||||
query='get_events',
|
||||
count=2,
|
||||
last_visit=last_visit
|
||||
)
|
||||
|
|
|
@ -32,7 +32,7 @@ from zerver.tornado.application import create_tornado_application
|
|||
from zerver.tornado import event_queue
|
||||
from zerver.tornado.event_queue import fetch_events, \
|
||||
allocate_client_descriptor, process_event
|
||||
from zerver.tornado.views import get_events_backend
|
||||
from zerver.tornado.views import get_events
|
||||
|
||||
from http.cookies import SimpleCookie
|
||||
import urllib.parse
|
||||
|
@ -256,7 +256,7 @@ class TornadoTestCase(WebSocketBaseTestCase):
|
|||
}
|
||||
])
|
||||
self.assertEqual(msg_resp[0], 'a')
|
||||
result = self.tornado_call(get_events_backend, profile,
|
||||
result = self.tornado_call(get_events, profile,
|
||||
{"queue_id": queue_events_data['response']['queue_id'],
|
||||
"user_client": "website",
|
||||
"last_event_id": -1,
|
||||
|
|
|
@ -35,6 +35,9 @@ def cleanup_event_queue(request: HttpRequest, user_profile: UserProfile,
|
|||
return json_success()
|
||||
|
||||
@asynchronous
|
||||
def get_events(request: HttpRequest, user_profile: UserProfile, handler: BaseHandler):
|
||||
return get_events_backend(request, user_profile, handler)
|
||||
|
||||
@has_request_variables
|
||||
def get_events_backend(request: HttpRequest, user_profile: UserProfile, handler: BaseHandler,
|
||||
user_client: Optional[Client]=REQ(converter=get_client, default=None),
|
||||
|
|
|
@ -70,7 +70,7 @@ def update_active_status_backend(request: HttpRequest, user_profile: UserProfile
|
|||
# (running as their user) has been active.
|
||||
try:
|
||||
activity = UserActivity.objects.get(user_profile = user_profile,
|
||||
query="get_events_backend",
|
||||
query="get_events",
|
||||
client__name="zephyr_mirror")
|
||||
|
||||
ret['zephyr_mirror_active'] = \
|
||||
|
|
|
@ -340,7 +340,7 @@ v1_api_and_json_patterns = [
|
|||
|
||||
# events -> zerver.tornado.views
|
||||
url(r'^events$', rest_dispatch,
|
||||
{'GET': 'zerver.tornado.views.get_events_backend',
|
||||
{'GET': 'zerver.tornado.views.get_events',
|
||||
'DELETE': 'zerver.tornado.views.cleanup_event_queue'}),
|
||||
|
||||
# report -> zerver.views.report
|
||||
|
|
Loading…
Reference in New Issue