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

Change recurringdonation status to exclude failed On STATS #1869

Merged
merged 1 commit into from
Nov 6, 2024

Conversation

CarlosQ96
Copy link
Collaborator

@CarlosQ96 CarlosQ96 commented Nov 5, 2024

Related to: https://github.com/orgs/Giveth/projects/9/views/1?sliceBy%5Bvalue%5D=CarlosQ96&pane=issue&itemId=85803313&issue=Giveth%7Canalytics-dashboard%7C42

Summary by CodeRabbit

  • New Features

    • Enhanced logic for counting and filtering recurring donations to provide a more comprehensive view by excluding failed donations.
  • Bug Fixes

    • Improved accuracy in donation counts across various methods to ensure consistent data aggregation.

@CarlosQ96 CarlosQ96 changed the title Change recurringdonation status to exclude failed Change recurringdonation status to exclude failed On STATS Nov 5, 2024
Copy link
Contributor

coderabbitai bot commented Nov 5, 2024

Walkthrough

The changes in this pull request primarily involve updates to the recurringDonationService.ts file. The logic for counting and filtering recurring donations has been modified to exclude donations with a status of FAILED. This adjustment affects several methods, including recurringDonationsCountPerDateRange, recurringDonationsCountPerDateRangePerMonth, recurringDonationsStreamedCUsdTotal, and recurringDonationsCountPerToken. The method signatures for these functions have also been updated to reflect the new filtering criteria, while existing error handling mechanisms remain unchanged.

Changes

File Change Summary
src/services/recurringDonationService.ts - Updated logic to exclude FAILED status in multiple donation counting methods.
- Modified method signatures for:
  • recurringDonationsCountPerDateRange
  • recurringDonationsCountPerDateRangePerMonth
  • recurringDonationsStreamedCUsdTotal
  • recurringDonationsStreamedCUsdTotalPerMonth
  • recurringDonationsCountPerToken

Possibly related PRs

  • feat: add tacking recurring donations queries #1704: This PR adds new asynchronous functions to recurringDonationService.ts, which are directly related to the changes made in the main PR that also modifies the logic and method signatures in the same file.
  • Query for recurring donation by date #1738: This PR introduces a new GraphQL query method in recurringDonationResolver.ts that utilizes the recurringDonationsCountPerDateRange and recurringDonationsCountPerDateRangePerMonth functions, which were updated in the main PR, indicating a direct relationship in functionality.

Suggested reviewers

  • mohammadranjbarz
  • RamRamez

🐰 In the garden where donations grow,
A change was made, as we now know.
Excluding failures, we count with glee,
Each gift that blooms, a joy to see!
With logic refined, our path is clear,
For every token, we hold dear.
Hoppy days ahead, let’s spread the cheer! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between f6d7b3f and a45c48c.

📒 Files selected for processing (1)
  • src/services/recurringDonationService.ts (3 hunks)
🔇 Additional comments (3)
src/services/recurringDonationService.ts (3)

480-481: LGTM! Change is consistent with previous method.

The modification to exclude FAILED status is consistent with the changes in recurringDonationsCountPerDateRange(). The query structure maintains proper performance with WHERE clause before GROUP BY.


675-676: LGTM! Change is consistent with other count methods.

The modification to exclude FAILED status is consistent with other counting methods. The query maintains proper structure and performance.


431-432: LGTM! Verify handling of other donation statuses.

The change from filtering only ACTIVE to excluding FAILED status looks good. This will now include donations with other statuses (PENDING, ACTIVE, ENDED) in the count.

Let's verify the impact on other recurring donation statuses:

✅ Verification successful

Let me analyze the results to verify the handling of other donation statuses.

From the search results, I can see:

  1. All possible statuses are used in the codebase: ACTIVE, PENDING, ENDED, FAILED, VERIFIED
  2. Status transitions are well-defined:
    • New donations start as PENDING
    • PENDING can transition to ACTIVE
    • PENDING can transition to FAILED
    • ACTIVE can transition to ENDED
  3. The test files show proper handling of all statuses in counting scenarios

Let me verify one more aspect - the other similar count queries in the file to ensure consistency:


Change is consistent and correctly handles all donation statuses

The verification confirms that:

  • All count queries in the service consistently exclude FAILED status
  • Status transitions are well-defined in the codebase (PENDING → ACTIVE/FAILED, ACTIVE → ENDED)
  • Test files demonstrate proper handling of all statuses (PENDING, ACTIVE, ENDED, FAILED, VERIFIED)
  • The change aligns with the business logic by including all non-FAILED donations in counts
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check usage of RECURRING_DONATION_STATUS across the codebase
# Expected: Find all status transitions and status checks to ensure they're handled correctly

# Search for status assignments and transitions
rg -A 3 "status = RECURRING_DONATION_STATUS" 

# Search for status checks in conditions
rg -A 3 "status === RECURRING_DONATION_STATUS"

Length of output: 8162


Script:

#!/bin/bash
# Check all count queries in recurringDonationService.ts
rg -A 3 "COUNT" src/services/recurringDonationService.ts

# Also check other WHERE clauses with status
rg -A 3 "where.*status" src/services/recurringDonationService.ts

Length of output: 1212

Comment on lines +675 to +676
.where('recurringDonation.status != :status', {
status: RECURRING_DONATION_STATUS.FAILED,
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider adding status filter to USD total methods.

While the count methods now consistently exclude FAILED status, the related methods recurringDonationsStreamedCUsdTotal() and recurringDonationsStreamedCUsdTotalPerMonth() don't have this filter. Consider adding the same status filter to maintain consistency.

Example implementation:

  const query = RecurringDonation.createQueryBuilder(
    'recurringDonation',
  ).select('COALESCE(SUM(recurringDonation.totalUsdStreamed), 0)', 'total')
+ .where('recurringDonation.status != :status', {
+   status: RECURRING_DONATION_STATUS.FAILED,
+ });

Committable suggestion skipped: line range outside the PR's diff.

@mateodaza mateodaza assigned mateodaza and unassigned mateodaza Nov 5, 2024
@mateodaza mateodaza self-requested a review November 5, 2024 22:31
Copy link
Member

@mateodaza mateodaza left a comment

Choose a reason for hiding this comment

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

👍🏼 👍🏼

@CarlosQ96 CarlosQ96 merged commit d2b614d into staging Nov 6, 2024
5 checks passed
@CarlosQ96 CarlosQ96 deleted the hotfix_recurring_donation_stats branch November 6, 2024 10:29
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