Stop using `Repo.preload` in loops - use `preload` in queries

Calling Repo.preload/2 inside Enum.map or comprehensions creates N+1 queries - one query to fetch the parent records, then one additional query for ea...
almirsarajcic

almirsarajcic

2 days ago

0

Use `Task.Supervisor` instead of bare `Task.async`

Bare Task.async creates linked tasks that can crash your process or leave zombie tasks running. Task.Supervisor provides supervised tasks with automat...
almirsarajcic

almirsarajcic

10 days ago

0

Prevent race conditions with `Ecto.Query.lock/2`

Two users buying the last item simultaneously can cause overselling. Use PostgreSQL row locks with lock: "FOR UPDATE" to prevent concurrent updates fr...
almirsarajcic

almirsarajcic

17 days ago

0

Use `temporary_assigns` for large lists in LiveView

Sending entire lists over the socket on every LiveView update kills performance. Mark list assigns as temporary to send them once and drop them from s...
almirsarajcic

almirsarajcic

24 days ago

0

Use `send_update_after/4` for delayed LiveComponent updates

Manual timer management with Process.send_after/3 in LiveComponents creates cleanup complexity. LiveView's send_update_after/4 handles delayed updates...
almirsarajcic

almirsarajcic

1 month ago

0

Use router `on_mount` hooks instead of duplicating LiveView mount logic

Copy-pasting the same assigns across every LiveView mount/3 function creates maintenance nightmares. Router-level on_mount hooks run automatically bef...
almirsarajcic

almirsarajcic

1 month ago

0

Stop mixing LiveView handlers with JavaScript hooks

Handling the same event in both Phoenix and JavaScript creates race conditions and unpredictable behavior. Keep server logic in LiveView handlers and ...
almirsarajcic

almirsarajcic

1 month ago

0

The amazing v/1 helper function

I may be late on this one but today I learned about the v/1, a helper function that retrieves the value from a previous expression by its line number ...
jrowah

jrowah

1 month ago

0

Phoenix contexts should return tuples, not raise

Phoenix context functions that raise exceptions break LiveView error handling and force try/catch everywhere. Tagged tuples enable composable error ha...
almirsarajcic

almirsarajcic

1 month ago

0

Prevent duplicate Oban jobs with `unique` worker options

Multiple button clicks or retries can enqueue the same background job multiple times, causing duplicate charges, emails, or API calls. Oban's built-in...
almirsarajcic

almirsarajcic

1 month ago

0

Stop rewriting Ecto queries from scratch - use `Ecto.Query.exclude/2` instead

Building complex queries often means starting with a base query, then customizing it for different use cases. Most developers duplicate the entire que...
almirsarajcic

almirsarajcic

2 months ago

0

Fixing `Ecto.StaleEntryError` with optimistic locking patterns

Race conditions in concurrent updates cause cryptic Ecto.StaleEntryError crashes in production. The error happens when multiple processes try to updat...
almirsarajcic

almirsarajcic

2 months ago

0

Phoenix application configuration

The config folder plays a pivotal role in any phoenix application. Its constituents are normally config.exs, dev.exs, prod.exs, runtime.exs and test.e...
Deankinyua

Deankinyua

2 months ago

0

Hunting down flaky tests with `--repeat-until-failure`

Nothing destroys developer confidence like tests that randomly fail in CI. One day your build is green, the next it's red with the exact same code. Th...
almirsarajcic

almirsarajcic

2 months ago

0

Impelementing Infinite Scroll in Phoenix

Infinite scroll is a listing-page design approach seen a lot on widely used apps such as TikTok and Instagram to keep the user engaged, loading additi...
Deankinyua

Deankinyua

2 months ago

0