-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Allow profile updates to happen on workers #3659
Changes from 11 commits
495cb10
cd97658
f81f421
484a0eb
54a9bea
a6c8137
38f708a
ca87ad1
782689b
91cdb6d
ab822a2
47b25ba
a81f140
8432e2e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Support profile API endpoints on workers |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,12 +32,12 @@ | |
logger = logging.getLogger(__name__) | ||
|
||
|
||
class ProfileHandler(BaseHandler): | ||
class WorkerProfileHandler(BaseHandler): | ||
PROFILE_UPDATE_MS = 60 * 1000 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these are redundant now |
||
PROFILE_UPDATE_EVERY_MS = 24 * 60 * 60 * 1000 | ||
|
||
def __init__(self, hs): | ||
super(ProfileHandler, self).__init__(hs) | ||
super(WorkerProfileHandler, self).__init__(hs) | ||
|
||
self.federation = hs.get_federation_client() | ||
hs.get_federation_registry().register_query_handler( | ||
|
@@ -46,11 +46,6 @@ def __init__(self, hs): | |
|
||
self.user_directory_handler = hs.get_user_directory_handler() | ||
|
||
if hs.config.worker_app is None: | ||
self.clock.looping_call( | ||
self._start_update_remote_profile_cache, self.PROFILE_UPDATE_MS, | ||
) | ||
|
||
@defer.inlineCallbacks | ||
def get_profile(self, user_id): | ||
target_user = UserID.from_string(user_id) | ||
|
@@ -282,6 +277,18 @@ def _update_join_states(self, requester, target_user): | |
room_id, str(e.message) | ||
) | ||
|
||
|
||
class MasterProfileHandler(WorkerProfileHandler): | ||
PROFILE_UPDATE_MS = 60 * 1000 | ||
PROFILE_UPDATE_EVERY_MS = 24 * 60 * 60 * 1000 | ||
|
||
def __init__(self, hs): | ||
super(MasterProfileHandler, self).__init__(hs) | ||
|
||
self.clock.looping_call( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we assert that |
||
self._start_update_remote_profile_cache, self.PROFILE_UPDATE_MS, | ||
) | ||
|
||
def _start_update_remote_profile_cache(self): | ||
return run_as_background_process( | ||
"Update remote profile", self._update_remote_profile_cache, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,7 +56,7 @@ | |
from synapse.handlers.message import EventCreationHandler, MessageHandler | ||
from synapse.handlers.pagination import PaginationHandler | ||
from synapse.handlers.presence import PresenceHandler | ||
from synapse.handlers.profile import ProfileHandler | ||
from synapse.handlers.profile import MasterProfileHandler, WorkerProfileHandler | ||
from synapse.handlers.read_marker import ReadMarkerHandler | ||
from synapse.handlers.receipts import ReceiptsHandler | ||
from synapse.handlers.room import RoomContextHandler, RoomCreationHandler | ||
|
@@ -308,7 +308,10 @@ def build_initial_sync_handler(self): | |
return InitialSyncHandler(self) | ||
|
||
def build_profile_handler(self): | ||
return ProfileHandler(self) | ||
if self.config.worker_app: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could we have this return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could, but this is how we do it for other handlers. I'm not sure I really think it'll be clearer moving it into the actual app There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hrm, ok, let's punt it for now, though I'm not sure I agree. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Certainly something we can revisit if/when we try and clean up the worker split out |
||
return WorkerProfileHandler(self) | ||
else: | ||
return MasterProfileHandler(self) | ||
|
||
def build_event_creation_handler(self): | ||
return EventCreationHandler(self) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,8 +71,6 @@ def get_from_remote_profile_cache(self, user_id): | |
desc="get_from_remote_profile_cache", | ||
) | ||
|
||
|
||
class ProfileStore(ProfileWorkerStore): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there not a danger of races if the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. on closer inspection, it looks like efforts are made to not call those methods from a worker, in which case I think they should probably stay in ProfileStore rather than moving. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Woops, fixed |
||
def create_profile(self, user_localpart): | ||
return self._simple_insert( | ||
table="profiles", | ||
|
@@ -96,6 +94,8 @@ def set_profile_avatar_url(self, user_localpart, new_avatar_url): | |
desc="set_profile_avatar_url", | ||
) | ||
|
||
|
||
class ProfileStore(ProfileWorkerStore): | ||
def add_remote_profile_cache(self, user_id, displayname, avatar_url): | ||
"""Ensure we are caching the remote user's profiles. | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given that this is also used as a base class on the master instance, can you either give it a different name (BaseProfileHandler?) or a docstring that explains the situation?