This issue has been migrated from [#15091](https://github.com/matrix-org/synapse/pull/15091). --- Fixes: #5677 <!-- --> <!-- Supersedes: # <!-- --> Follows: #14756 <!-- --> <!-- Part of: # <!-- --> Base: `rei/userdirpriv2_refresh_remotes` <!-- git-stack-base-branch:rei/userdirpriv2_refresh_remotes --> This pull request is commit-by-commit review friendly. <!-- --> <!-- This pull request is intended for commit-by-commit review. <!-- --> Original commit schedule, with full messages: <ol> <li> Rename method to make obvious it only applies to local users </li> <li> Add another temporary table to the user directory background update for storing remote users needing lookup </li> <li> Don't add private remote users straight to the user directory \ Instead, queue them up to be added to the stale profile queue. </li> <li> Add a background update stage to sort the remote users into the stale profile queue as appropriate </li> <li> (ugly?) Kick off the fetching of remote profiles once ready </li> <li> When we start populating the user directory, clear out the old tables first if they're there </li> <li> When rebuilding user dir, schedule the new task </li> <li> Schedule a user directory rebuild </li> </ol> <!---GHSTACKOPEN--> ### Stacked PR Chain: rei:userdirpriv | PR | Title | Status | Merges Into | |:--:|:------|:-------|:-------------:| |#14755|Preparatory work to fix the user directory assuming that any remote membership state events represent a profile change.||-| |#14756|Refresh remote profiles that have been marked as stale, in order to fill the user directory.||#14755| |#15091|👉 *(Draft) When populating the user directory, query remote servers for user profiles instead of leaking the profiles in private rooms.*||#14756| <!---GHSTACKCLOSE-->