fix: count distinct districts/IPs instead of total rows in reportValidation.service.ts (#1967)#2139
Merged
dipexplorer merged 1 commit intoJun 20, 2026
Conversation
…dation.service.ts (RatLoopz#1967)
Contributor
|
🎉 Congratulations @nimkarprachi17! Your Pull Request "fix: count distinct districts/IPs instead of total rows in reportValidation.service.ts (#1967)" has been successfully merged by @dipexplorer. Thank you for your valuable contribution to SahiDawa! 🇮🇳 Follow us on LinkedIn: https://www.linkedin.com/company/ratloopz/ to get shoutout |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🛑 STOP: Assignment & File Scope Check
📋 PR Summary & Link
apps/api/src/services/reportValidation.service.tswhere the geographic spread check and both Sybil detection checks usedselect(column, { count: "exact", head: true }), which returns the total row count matching the filter, not a distinct count. This meant 5 duplicate reports from the same IP/district were incorrectly counted as 5 distinct districts/reporters. Fixed by fetching the actual rows and computing distinct counts in JavaScript with aSet, since the lookback window (burstDeadline, last hour) keeps the result set small. Added unit tests inapps/api/tests/reportValidation.service.test.tsverifying duplicate reports from the same IP/district do not trigger the distinct-value thresholds, while genuinely distinct districts/IPs still correctly trigger them.📸 Proof of Work (Screenshots / Logs)
🏷️ PR Type
type: bugtype: testing✅ Checklist
Closes #1967)mainand resolved any conflictsFiles changed:
apps/api/src/services/reportValidation.service.ts— fixed 3 distinct-count queries (geographic spread, Sybil-by-district, Sybil-by-medicine) to useSet-based distinct counting instead ofcount: "exact"row countsapps/api/tests/reportValidation.service.test.ts— new file, 4 unit tests covering both the bug scenario (duplicate reports not over-counted) and the correct-detection scenario (genuinely distinct districts/IPs still flagged)