diff --git a/synapse/handlers/profile.py b/synapse/handlers/profile.py
index 239b0aa744..6eed3826a7 100644
--- a/synapse/handlers/profile.py
+++ b/synapse/handlers/profile.py
@@ -23,14 +23,7 @@ from synapse.api.errors import (
StoreError,
SynapseError,
)
-from synapse.metrics.background_process_metrics import wrap_as_background_process
-from synapse.types import (
- JsonDict,
- Requester,
- UserID,
- create_requester,
- get_domain_from_id,
-)
+from synapse.types import JsonDict, Requester, UserID, create_requester
from synapse.util.caches.descriptors import cached
from synapse.util.stringutils import parse_and_validate_mxc_uri
@@ -50,9 +43,6 @@ class ProfileHandler:
delegate to master when necessary.
"""
- PROFILE_UPDATE_MS = 60 * 1000
- PROFILE_UPDATE_EVERY_MS = 24 * 60 * 60 * 1000
-
def __init__(self, hs: "HomeServer"):
self.store = hs.get_datastores().main
self.clock = hs.get_clock()
@@ -73,11 +63,6 @@ class ProfileHandler:
self._third_party_rules = hs.get_third_party_event_rules()
- if hs.config.worker.run_background_tasks:
- self.clock.looping_call(
- self._update_remote_profile_cache, self.PROFILE_UPDATE_MS
- )
-
async def get_profile(self, user_id: str) -> JsonDict:
target_user = UserID.from_string(user_id)
@@ -116,30 +101,6 @@ class ProfileHandler:
raise SynapseError(502, "Failed to fetch profile")
raise e.to_synapse_error()
- async def get_profile_from_cache(self, user_id: str) -> JsonDict:
- """Get the profile information from our local cache. If the user is
- ours then the profile information will always be correct. Otherwise,
- it may be out of date/missing.
- """
- target_user = UserID.from_string(user_id)
- if self.hs.is_mine(target_user):
- try:
- displayname = await self.store.get_profile_displayname(
- target_user.localpart
- )
- avatar_url = await self.store.get_profile_avatar_url(
- target_user.localpart
- )
- except StoreError as e:
- if e.code == 404:
- raise SynapseError(404, "Profile was not found", Codes.NOT_FOUND)
- raise
-
- return {"displayname": displayname, "avatar_url": avatar_url}
- else:
- profile = await self.store.get_from_remote_profile_cache(user_id)
- return profile or {}
-
async def get_displayname(self, target_user: UserID) -> Optional[str]:
if self.hs.is_mine(target_user):
try:
@@ -509,45 +470,3 @@ class ProfileHandler:
# so we act as if we couldn't find the profile.
raise SynapseError(403, "Profile isn't available", Codes.FORBIDDEN)
raise
-
- @wrap_as_background_process("Update remote profile")
- async def _update_remote_profile_cache(self) -> None:
- """Called periodically to check profiles of remote users we haven't
- checked in a while.
- """
- entries = await self.store.get_remote_profile_cache_entries_that_expire(
- last_checked=self.clock.time_msec() - self.PROFILE_UPDATE_EVERY_MS
- )
-
- for user_id, displayname, avatar_url in entries:
- is_subscribed = await self.store.is_subscribed_remote_profile_for_user(
- user_id
- )
- if not is_subscribed:
- await self.store.maybe_delete_remote_profile_cache(user_id)
- continue
-
- try:
- profile = await self.federation.make_query(
- destination=get_domain_from_id(user_id),
- query_type="profile",
- args={"user_id": user_id},
- ignore_backoff=True,
- )
- except Exception:
- logger.exception("Failed to get avatar_url")
-
- await self.store.update_remote_profile_cache(
- user_id, displayname, avatar_url
- )
- continue
-
- new_name = profile.get("displayname")
- if not isinstance(new_name, str):
- new_name = None
- new_avatar = profile.get("avatar_url")
- if not isinstance(new_avatar, str):
- new_avatar = None
-
- # We always hit update to update the last_check timestamp
- await self.store.update_remote_profile_cache(user_id, new_name, new_avatar)
|