I was reading the documentation about Presence metadata and came across this bit: Phoenix.Presence — Phoenix v1.6.2
"Presence metadata should be minimized and used to store small, ephemeral state, such as a user’s “online” or “away” status. More detailed information, such as user details that need to be fetched from the database"
Question: Why is it recommended that presence metadata be minimized? Does too much metadata slow down the system or something?
The reason I’m asking is because I had a nice set up where when a user joins a chat room, I run this script:
def handle_info(:after_join, socket) do
{:ok, _} = Presence.track(socket, "#{socket.assigns.user_id}", %{
online_at: inspect(System.system_time(:second)),
status: socket.assigns.status,
profilephoto: socket.assigns.photo,
username: socket.assigns.username,
gender: socket.assigns.gender
})
push(socket, "presence_state", Presence.list(socket))
{:noreply, socket}
end
It tracks the user to the Presence setup for the room, so users can see them online. At the same time, this takes the data assigned set on the user’s socket, and attaches it to the Presence, passing along a few basic snippets such as the user’s profile image, username, etc, so that a user’s basic stuff renders nicely on the client side, as a user joining a chat room.
Is this the incorrect way of doing this? In the documentation, it recommends using “fetch” to fetch user details from the database instead of storing it in the Presence. Seems like it would be much easier copying the existing data from a socket and putting it in the Presence?
Or are they recommending using client-side AJAX or something to fetch each user’s details after they appear in the room?