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

src/donations: Fix wrong unique donors count #581

Merged
merged 1 commit into from
Dec 12, 2023

Conversation

sashko9807
Copy link
Member

Currently when we count unique donors we group them by billing_name, which gives us the total number of unique donors. The number of total donors is then added, to the total amount of donations made by the first user in the returned query. This results in overestimating the actual count of unique donors.

Changed the query to plain SQL, as prisma doesn't yet support counting by distinct properties, and counting is relatively faster to process, than grouping or searching

Changed the query to count by distinct billing_email property, rather than billing_name, as email is the "more unique" property of the two.

Currently when we count unique donors we group them by billing_name, which gives us the total number of unique donors.
The number of total donors is then added, to the total amount of donations made by the first user in the returned query. This results in overestimating the actually count of unique donors.

Changed the query to plain SQL, as prisma doesn't yet support counting by distinct properties, and counting is relatively faster to process, than grouping or searching
Changed the query to count by distinct billing_email property, rather than billing_name, as email is the "more unique" property of the two.
Copy link

github-actions bot commented Dec 7, 2023

✅ Tests will run for this PR. Once they succeed it can be merged.


// get count of the donations with billingName == null
const anonymousDonations = donorsCount[0]._count._all
const donorsCount = await this.prisma.$queryRaw<{
Copy link
Contributor

Choose a reason for hiding this comment

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

queryRaw - this is usefull to learn :)

@slavcho slavcho added the run tests Allows running the tests workflows for forked repos label Dec 12, 2023
@github-actions github-actions bot removed the run tests Allows running the tests workflows for forked repos label Dec 12, 2023
@slavcho slavcho merged commit ade7ae1 into podkrepi-bg:master Dec 12, 2023
11 of 12 checks passed
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