Hi, I have a notification part on my project which has 2 schema tables:
-
notifs
= notifications is sent by system or moderator users -
user_notif_status
=read
orskipped
notifications of user.
Imagine in this forum you have a profile picture in the top of the right side that shows you how many notifications you have 3 or 20, it counts them for you. If you clicked on it, you can see your last 10 notifications with status, you have read or not!
Then, if I make a query for loading last 10 queries, I do like this:
from(n in Notifs, left_join: s in assoc(n, :user_notif_status))
It is okay for now, but I have a problem when I want to count all the unread notification. I think these are separate queries and different. I could not use subquery
because it loads my counter every record and I don’t want it, I just want to load counter one time.
Furthermore, I have 2 solutions on my mind:
- use elixir
task
to send 2 queries and show it to my user. - load 2 different queries.
Please suggest me what to do that is better for load time when I have a big database on my projects.
Thanks