shahryarjb
What is the best way to load two different queries? (Elixir Task? Or etc.)
Hi, I have a notification part on my project which has 2 schema tables:
notifs= notifications is sent by system or moderator usersuser_notif_status=readorskippednotifications 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
taskto 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
Most Liked
APB9785
Ah. I think it’s fine to use Task for multiple async queries, since Ecto does this under the hood also. But since the count query must check the entire table, there is potentially a faster way: adding an unread_count column for each user, which gets updated during transactions where a notification is created, read, or skipped. Since it removes work from each read, but adds work to each write, this would be optimal for situations where page loads are more common than new notifications.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









