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

Send Notifications to donors and people who liked the projects #700

Merged
merged 2 commits into from
Oct 27, 2022

Conversation

mohammadranjbarz
Copy link
Collaborator

related to #699

@mohammadranjbarz mohammadranjbarz marked this pull request as ready for review October 25, 2022 13:32
Copy link
Collaborator

@CarlosQ96 CarlosQ96 left a comment

Choose a reason for hiding this comment

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

Hey Mohammad thanks, I agree we gotta enqueue the events as they can be too many. So I think bull is awesome here.
However I have some suggestions to improve code:

  1. With a different typeorm Query (getRawMany and LOWER). We can remove 1 extra loop for more efficiency.
  2. I think relationId deletes column data, so we have to do a leftJoin without relation.

@Field(type => ID)
@Column()
@RelationId((reaction: Reaction) => reaction.user)
Copy link
Collaborator

@CarlosQ96 CarlosQ96 Oct 26, 2022

Choose a reason for hiding this comment

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

As much as I know this is the right way, this will most likely delete the data from the UserId column, by running a query on relationId to set the column. (Because we using sync.)

Confirm this isn't the case and we can proceed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Else we will have to do a different query.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Rest assured... leftJoins work without the need of relationId or ManyToOne, they are a bit less efficient because they don't have an index. But I think we can add it separately (haven't test this).

      .leftJoin(User, 'user', 'reaction.userId = user.id')

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh nice catch, thank you I rewrite that function considering all your feedback, it works now


return donations.map(donation => {
return {
walletAddress: donation.user.walletAddress?.toLowerCase() as string,
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can avoid this loop entirely by using .getRawMany() instead, this returns the selected data only as json and not entity mapped data.
And in the select you can do directly:

.select('LOWER(user.walletAddress) AS "walletAddress", user.email as email')

This should return:

[{ walletAddress: 'xxxxx', email: 'xxxx' }]

Copy link
Collaborator

Choose a reason for hiding this comment

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

From what I see in the code we have 2 loops,
Fetch query -> map data correctly -> map to enqueue.

If we delete the middle map this would greatly decrease code complexity.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

return {
walletAddress: reaction.user.walletAddress?.toLowerCase() as string,
email: reaction.user.email,
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as the donation repository, to avoid extra processing and loops.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

projectId: number,
): Promise<{ walletAddress: string; email?: string }[]> => {
const reactions = await Reaction.createQueryBuilder('reaction')
.leftJoin('reaction.user', 'user')
Copy link
Collaborator

Choose a reason for hiding this comment

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

If relationId deletes column, like in other comment. Remove it and add:

      .leftJoin(User, 'user', 'reaction.userId = user.id')

Copy link
Collaborator

@CarlosQ96 CarlosQ96 left a comment

Choose a reason for hiding this comment

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

Awesome! You can merge 👍 thanks

@mohammadranjbarz mohammadranjbarz merged commit 641c191 into staging Oct 27, 2022
@aminlatifi aminlatifi deleted the f_699_send_notifications-to_donors branch January 25, 2023 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants