Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(api-service,dashboard): Replace create_at sorting with _id for subscribers #7603

Merged
merged 1 commit into from
Jan 29, 2025

Conversation

desiprisg
Copy link
Contributor

What changed? Why was the change needed?

Screenshots

Expand for optional sections

Related enterprise PR

Special notes for your reviewer

Copy link

netlify bot commented Jan 28, 2025

Deploy Preview for dev-web-novu ready!

Name Link
🔨 Latest commit b600c92
🔍 Latest deploy log https://app.netlify.com/sites/dev-web-novu/deploys/679a112a6ab13300086ceeeb
😎 Deploy Preview https://deploy-preview-7603.dashboard.novu-staging.co
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Jan 28, 2025

Deploy Preview for dashboard-v2-novu-staging ready!

Name Link
🔨 Latest commit b600c92
🔍 Latest deploy log https://app.netlify.com/sites/dashboard-v2-novu-staging/deploys/679a112ae465ea0008b6a641
😎 Deploy Preview https://deploy-preview-7603.dashboard-v2.novu-staging.co
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

pkg-pr-new bot commented Jan 28, 2025

Open in Stackblitz

@novu/client

npm i https://pkg.pr.new/novuhq/novu/@novu/client@7603

@novu/headless

npm i https://pkg.pr.new/novuhq/novu/@novu/headless@7603

@novu/node

npm i https://pkg.pr.new/novuhq/novu/@novu/node@7603

@novu/notification-center

npm i https://pkg.pr.new/novuhq/novu/@novu/notification-center@7603

novu

npm i https://pkg.pr.new/novuhq/novu@7603

@novu/providers

npm i https://pkg.pr.new/novuhq/novu/@novu/providers@7603

@novu/shared

npm i https://pkg.pr.new/novuhq/novu/@novu/shared@7603

commit: b600c92

@@ -28,7 +28,7 @@ export class SubscriberController {
after: query.after,
before: query.before,
orderDirection: query.orderDirection || DirectionEnum.DESC,
orderBy: query.orderBy || 'createdAt',
orderBy: query.orderBy || '_id',
Copy link
Contributor

@djabarovgeorge djabarovgeorge Jan 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorting by id is an internal implementation detail.
we need to map createdAt to id internally.

question: what will happen if the client will send orderBy = createdAt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO since it has its drawbacks we should keep it as _id. It's not correct to expose it as createdAt.

Comment on lines -196 to -201
subscriberSchema.index({
_environmentId: 1,
_organizationId: 1,
createdAt: 1,
_id: 1,
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we sort by _id we will still need index for it.
something like

subscriberSchema.index({
  _environmentId: 1,
  _organizationId: 1,
  _id: 1,
});

id suggest to check if we need

subscriberSchema.index({
  _environmentId: 1,
  _organizationId: 1,
  deleted: 1,
});

if we do not we could remove it and add the suggested above instead.

@@ -10,7 +10,7 @@ export interface IListSubscribersRequestDto {

orderDirection: DirectionEnum;

orderBy: 'updatedAt' | 'createdAt';
orderBy: 'updatedAt' | '_id';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as mentioned above IMO we should encapsulate internal implementation on the API interface, the client should sort createdAt and we will map it to sort by _id

Copy link
Contributor

@djabarovgeorge djabarovgeorge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now that i am looking at the index we have, I don't know how much we benefit by sorting by _id.
why do we need the _id at the index at all? as long as we do not "range" by it. it is not needed.

subscriberSchema.index({
  _environmentId: 1,
  _organizationId: 1,
  createdAt: -1,
});

cc @desiprisg

@desiprisg desiprisg merged commit 4c89794 into next Jan 29, 2025
40 of 41 checks passed
@desiprisg desiprisg deleted the replace_created_at_with_id_subscribers branch January 29, 2025 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants