Repository navigation
Index notification by channel and recipient for feed queries #17781
gregbarajas
started this conversation in
Feature Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Environment
@mercurjs/core), Medusa 2.22.3 (@medusajs/notification)dist/migrationsof@medusajs/notification2.22.3, not a forkProblem / current behavior
The
notificationtable has indexes ondeleted_at,idempotency_key,provider_idandreceiver_idonly (@medusajs/notification/dist/migrations/Migration20240628075401.js,Migration20240830094712.js,Migration20250120110514.js). A notification feed reads one recipient's notifications on one channel, newest first:channel = 'feed' AND "to" = :recipient ORDER BY created_at DESC LIMIT n, throughlistNotifications({ channel, to }, { order: { created_at: "DESC" }, take })or SQL. No index serves that filter, so every feed load scans the whole table, which grows with every email, SMS and feed notification the store sends.Proposed solution / API
A migration in
@medusajs/notification:No API change.
Why core
Any project that shows a per-recipient notification feed (Medusa's admin feed, a vendor or customer inbox) runs this query, and the table grows with every notification sent. Indexing a core table from a project migration risks clashing with a later core migration, so the index belongs in the module that owns the table.
Our workaround
We add the same index from our own project migration, on a table our project doesn't own. It works, but core doesn't know the index exists, and a future core migration on the same columns could duplicate or clash with it. We'll drop ours once core ships one.
Why it matters
Feed loads stay fast as notification volume grows, for every Medusa store with a feed.
Affected apps
Suggested implementation notes
packages/modules/notification/src/models/notification.tspackages/modules/notification/src/migrations/All reactions