shahryarjb

shahryarjb

Hi, I have a notification part on my project which has 2 schema tables:

  1. notifs = notifications is sent by system or moderator users
  2. user_notif_status = read or skipped 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:

  1. use elixir task to send 2 queries and show it to my user.
  2. 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

Showing Posts 1 to 3

APB9785

APB9785

Creator of ECSx

If your first query is fetching both read and unread notifications, you could pass the results into Enum.count/2

shahryarjb

shahryarjb OP

I am using paginate and do not load all the records parameters, I just load last 10

  • count all records on my db
  • load last 10 notifications

see these images

Screen Shot 1400-07-15 at 19.38.17

APB9785

APB9785

Creator of ECSx

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.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
ryanwinchester
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted” Version...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews