mirror of
https://github.com/zulip/zulip.git
synced 2025-11-12 09:58:06 +00:00
zerver/lib: Use python 3 syntax for typing.
Extracted from a larger commit by tabbott because these changes will not create significant merge conflicts.
This commit is contained in:
@@ -22,8 +22,7 @@ from django.db.models import Q
|
||||
|
||||
MESSAGE_CACHE_SIZE = 75000
|
||||
|
||||
def message_fetch_objects():
|
||||
# type: () -> List[Any]
|
||||
def message_fetch_objects() -> List[Any]:
|
||||
try:
|
||||
max_id = Message.objects.only('id').order_by("-id")[0].id
|
||||
except IndexError:
|
||||
@@ -31,8 +30,8 @@ def message_fetch_objects():
|
||||
return Message.objects.select_related().filter(~Q(sender__email='tabbott/extra@mit.edu'),
|
||||
id__gt=max_id - MESSAGE_CACHE_SIZE)
|
||||
|
||||
def message_cache_items(items_for_remote_cache, message):
|
||||
# type: (Dict[Text, Tuple[bytes]], Message) -> None
|
||||
def message_cache_items(items_for_remote_cache: Dict[Text, Tuple[bytes]],
|
||||
message: Message) -> None:
|
||||
'''
|
||||
Note: this code is untested, and the caller has been
|
||||
commented out for a while.
|
||||
@@ -41,32 +40,32 @@ def message_cache_items(items_for_remote_cache, message):
|
||||
value = MessageDict.to_dict_uncached(message)
|
||||
items_for_remote_cache[key] = (value,)
|
||||
|
||||
def user_cache_items(items_for_remote_cache, user_profile):
|
||||
# type: (Dict[Text, Tuple[UserProfile]], UserProfile) -> None
|
||||
def user_cache_items(items_for_remote_cache: Dict[Text, Tuple[UserProfile]],
|
||||
user_profile: UserProfile) -> None:
|
||||
items_for_remote_cache[user_profile_by_email_cache_key(user_profile.email)] = (user_profile,)
|
||||
items_for_remote_cache[user_profile_by_id_cache_key(user_profile.id)] = (user_profile,)
|
||||
items_for_remote_cache[user_profile_by_api_key_cache_key(user_profile.api_key)] = (user_profile,)
|
||||
items_for_remote_cache[user_profile_cache_key(user_profile.email, user_profile.realm)] = (user_profile,)
|
||||
|
||||
def stream_cache_items(items_for_remote_cache, stream):
|
||||
# type: (Dict[Text, Tuple[Stream]], Stream) -> None
|
||||
def stream_cache_items(items_for_remote_cache: Dict[Text, Tuple[Stream]],
|
||||
stream: Stream) -> None:
|
||||
items_for_remote_cache[get_stream_cache_key(stream.name, stream.realm_id)] = (stream,)
|
||||
|
||||
def client_cache_items(items_for_remote_cache, client):
|
||||
# type: (Dict[Text, Tuple[Client]], Client) -> None
|
||||
def client_cache_items(items_for_remote_cache: Dict[Text, Tuple[Client]],
|
||||
client: Client) -> None:
|
||||
items_for_remote_cache[get_client_cache_key(client.name)] = (client,)
|
||||
|
||||
def huddle_cache_items(items_for_remote_cache, huddle):
|
||||
# type: (Dict[Text, Tuple[Huddle]], Huddle) -> None
|
||||
def huddle_cache_items(items_for_remote_cache: Dict[Text, Tuple[Huddle]],
|
||||
huddle: Huddle) -> None:
|
||||
items_for_remote_cache[huddle_hash_cache_key(huddle.huddle_hash)] = (huddle,)
|
||||
|
||||
def recipient_cache_items(items_for_remote_cache, recipient):
|
||||
# type: (Dict[Text, Tuple[Recipient]], Recipient) -> None
|
||||
def recipient_cache_items(items_for_remote_cache: Dict[Text, Tuple[Recipient]],
|
||||
recipient: Recipient) -> None:
|
||||
items_for_remote_cache[get_recipient_cache_key(recipient.type, recipient.type_id)] = (recipient,)
|
||||
|
||||
session_engine = import_module(settings.SESSION_ENGINE)
|
||||
def session_cache_items(items_for_remote_cache, session):
|
||||
# type: (Dict[Text, Text], Session) -> None
|
||||
def session_cache_items(items_for_remote_cache: Dict[Text, Text],
|
||||
session: Session) -> None:
|
||||
store = session_engine.SessionStore(session_key=session.session_key) # type: ignore # import_module
|
||||
items_for_remote_cache[store.cache_key] = store.decode(session.session_data)
|
||||
|
||||
@@ -89,8 +88,7 @@ cache_fillers = {
|
||||
'session': (lambda: Session.objects.all(), session_cache_items, 3600*24*7, 10000),
|
||||
} # type: Dict[str, Tuple[Callable[[], List[Any]], Callable[[Dict[Text, Any], Any], None], int, int]]
|
||||
|
||||
def fill_remote_cache(cache):
|
||||
# type: (str) -> None
|
||||
def fill_remote_cache(cache: str) -> None:
|
||||
remote_cache_time_start = get_remote_cache_time()
|
||||
remote_cache_requests_start = get_remote_cache_requests()
|
||||
items_for_remote_cache = {} # type: Dict[Text, Any]
|
||||
|
||||
Reference in New Issue
Block a user