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

fix: Deleting the override doesn't remove it from the overrides. Refreshing it will give you a client side error. #2246 #2341

Merged
merged 3 commits into from
Oct 29, 2024

Conversation

kohi9noor
Copy link
Contributor

@kohi9noor kohi9noor commented Oct 11, 2024

const namespace = await db.query.ratelimitNamespaces.findFirst({
    where: (table, { eq, and, isNull }) =>
      and(
        eq(table.id, props.params.namespaceId),
        isNull(table.deletedAt)
      ),
    with: {
      overrides: {
        columns: {
          id: true,
          identifier: true,
          limit: true,
          duration: true,
          async: true,
        },
        where: (table, { isNull }) =>  // excluding soft deletes columns
          isNull(table.deletedAt) 
      },
      workspace: {
        columns: {
          id: true,
          tenantId: true,
          features: true,
        },
      },
    },
  });

What does this PR do?

This PR ensures that soft-deleted records are excluded when querying the ratelimitNamespaces, overrides, and workspace tables. Specifically, it filters out records where the deletedAt column is not NULL, thereby preventing outdated or deleted data from being returned. This resolves an issue related to the improper display of soft-deleted records.


Type of Change

  • Bug Fix (non-breaking change which fixes an issue)
  • Chore (refactoring code, technical debt, workflow improvements)
  • Enhancement (small improvements)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update


Checklist

Required

  • Filled out the "How to test" section in this PR
  • Read Contributing Guide
  • Self-reviewed my own code
  • Commented on my code in hard-to-understand areas
  • Ran pnpm build
  • Ran pnpm fmt
  • Checked for warnings, there are none
  • Removed all console.logs
  • Merged the latest changes from main onto my branch with git pull origin main
  • My changes don't cause any responsiveness issues
    4e50f2a6-55ac-45f2-a20e-b442e99fb026.webm

Summary by CodeRabbit

  • New Features
    • Improved filtering for ratelimit overrides to exclude deleted entries.
  • Bug Fixes
    • Enhanced query logic for better accuracy in data retrieval.
  • Style
    • Reformatted query conditions for improved readability.

  const namespace = await db.query.ratelimitNamespaces.findFirst({
    where: (table, { eq, and, isNull }) =>
      and(
        eq(table.id, props.params.namespaceId),
        isNull(table.deletedAt)
      ),
    with: {
      overrides: {
        columns: {
          id: true,
          identifier: true,
          limit: true,
          duration: true,
          async: true,
        },
        where: (table, { isNull }) =>  // excluding soft deletes columns
          isNull(table.deletedAt) 
      },
      workspace: {
        columns: {
          id: true,
          tenantId: true,
          features: true,
        },
      },
    },
  });
Copy link

changeset-bot bot commented Oct 11, 2024

⚠️ No Changeset found

Latest commit: 50681f6

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Oct 11, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
engineering ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 28, 2024 3:00pm

@CLAassistant
Copy link

CLAassistant commented Oct 11, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

coderabbitai bot commented Oct 11, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes made in the pull request focus on the OverridePage component within the apps/dashboard/app/(app)/ratelimits/[namespaceId]/overrides/page.tsx file. The primary modification involves restructuring the database query to include an additional condition that filters out deleted overrides by checking for isNull(table.deletedAt). This adjustment enhances the filtering logic while maintaining the overall functionality and rendering logic of the component.

Changes

File Path Change Summary
apps/dashboard/app/(app)/ratelimits/[namespaceId]/overrides/page.tsx Modified the overrides query to include a condition for non-deleted overrides (isNull(table.deletedAt)). Adjusted formatting for improved readability of the and conditions. Rendering logic remains unchanged.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant OverridePage
    participant Database

    User->>OverridePage: Request to view overrides
    OverridePage->>Database: Fetch overrides with condition (isNull(table.deletedAt))
    Database-->>OverridePage: Return non-deleted overrides
    OverridePage-->>User: Display overrides or empty placeholder
Loading

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

vercel bot commented Oct 11, 2024

@kohi9noor is attempting to deploy a commit to the Unkey Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

github-actions bot commented Oct 11, 2024

Thank you for following the naming conventions for pull request titles! 🙏

@kohi9noor kohi9noor changed the title Fix: Deleting the override doesn't remove it from the overrides. Refreshing it will give you a client side error. #2246 fix: Deleting the override doesn't remove it from the overrides. Refreshing it will give you a client side error. #2246 Oct 11, 2024
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: 0

🧹 Outside diff range and nitpick comments (2)
apps/dashboard/app/(app)/ratelimits/[namespaceId]/overrides/page.tsx (2)

39-40: Effective filtering of deleted overrides

The addition of the where clause in the overrides query is an excellent improvement:

  1. It directly addresses the PR objective by filtering out soft-deleted overrides.
  2. This change will prevent client-side errors when refreshing, as mentioned in the PR objectives.

For consistency with the namespace query, consider using the and function, even though there's currently only one condition. This will make future additions easier:

-where: (table, { isNull }) => 
-  isNull(table.deletedAt) 
+where: (table, { and, isNull }) =>
+  and(
+    isNull(table.deletedAt)
+  )

Additional ratelimitNamespaces.findFirst Queries Missing deletedAt Filters

The following files contain ratelimitNamespaces.findFirst queries without deletedAt filters and should be updated to maintain data integrity:

  • apps/dashboard/app/(app)/ratelimits/[namespaceId]/page.tsx
  • apps/dashboard/app/(app)/ratelimits/[namespaceId]/logs/page.tsx
  • apps/dashboard/app/(app)/ratelimits/[namespaceId]/layout.tsx
  • apps/dashboard/app/(app)/@breadcrumb/ratelimits/[namespaceId]/page.tsx
  • apps/dashboard/app/(app)/@breadcrumb/ratelimits/[namespaceId]/logs/page.tsx
  • apps/dashboard/app/(app)/@breadcrumb/ratelimits/[namespaceId]/settings/page.tsx
  • apps/api/src/routes/v1_ratelimit_limit.ts

These instances need to include deletedAt null checks to ensure consistency and prevent potential data issues.

🔗 Analysis chain

Line range hint 1-89: Summary of changes and their impact

The modifications in this file effectively address the PR objectives:

  1. Both namespace and override queries now filter out soft-deleted records.
  2. These changes prevent client-side errors when refreshing and ensure that only valid data is displayed.
  3. The implementation is consistent across queries and improves overall data integrity.

The rest of the file, including the component's rendering logic, remains unchanged. This focused approach minimizes the risk of introducing new issues while solving the targeted problem.

To ensure that these changes don't affect other parts of the application, please run the following verification:

This script will help identify any other locations where similar changes might be necessary to maintain consistency across the application.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any other usage of ratelimitNamespaces or overrides queries that might need similar updates

# Search for ratelimitNamespaces queries
echo "Searching for ratelimitNamespaces queries:"
rg --type typescript 'ratelimitNamespaces\.findFirst' --glob '!**/overrides/page.tsx'

# Search for overrides queries
echo "Searching for overrides queries:"
rg --type typescript 'overrides:.*where:' --glob '!**/overrides/page.tsx'

Length of output: 403


Script:

#!/bin/bash
# Description: Check for any other usage of ratelimitNamespaces or overrides queries that might need similar updates

# Search for ratelimitNamespaces queries in TypeScript files excluding overrides/page.tsx
echo "Searching for ratelimitNamespaces queries:"
rg 'ratelimitNamespaces\.findFirst' -g '*.ts' -g '*.tsx' --glob '!apps/dashboard/app/(app)/ratelimits/[namespaceId]/overrides/page.tsx'

# Search for overrides queries in TypeScript files excluding overrides/page.tsx
echo "Searching for overrides queries:"
rg 'overrides\s*:\s*.*where\s*:' -g '*.ts' -g '*.tsx' --glob '!apps/dashboard/app/(app)/ratelimits/[namespaceId]/overrides/page.tsx'

Length of output: 1696


Script:

#!/bin/bash
# Description: Identify ratelimitNamespaces.findFirst queries without deletedAt null checks

echo "Searching for ratelimitNamespaces.findFirst queries without deletedAt filters:"

# Find all ratelimitNamespaces.findFirst usages in .ts and .tsx files, excluding the overrides/page.tsx
rg 'ratelimitNamespaces\.findFirst' -g '*.ts' -g '*.tsx' --glob '!apps/dashboard/app/(app)/ratelimits/[namespaceId]/overrides/page.tsx' \
| grep -v 'deletedAt'

Length of output: 1578

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7690697 and 40c3e05.

📒 Files selected for processing (1)
  • apps/dashboard/app/(app)/ratelimits/[namespaceId]/overrides/page.tsx (2 hunks)
🧰 Additional context used
🔇 Additional comments (1)
apps/dashboard/app/(app)/ratelimits/[namespaceId]/overrides/page.tsx (1)

26-29: Improved query structure and data integrity

The restructuring of the where clause for the namespace query is a positive change:

  1. It improves code readability by separating conditions.
  2. The addition of isNull(table.deletedAt) ensures that only non-deleted namespaces are retrieved, which aligns with the PR objective of excluding soft-deleted records.

This change enhances data integrity and prevents potential issues with deleted namespaces.

@perkinsjr
Copy link
Collaborator

Hi @kohi9noor this issue is assigned to another user.

Please do not work on issues unless they are approved and assigned to you. It is unfair to other participants

@chronark chronark added the Requires CLA Waiting for a contributor to sign the CLA label Oct 28, 2024
@chronark
Copy link
Collaborator

@kohi9noor please sign the CLA

@chronark chronark self-assigned this Oct 28, 2024
@kohi9noor
Copy link
Contributor Author

@chronark done I have signed the CLA

@chronark chronark merged commit 21dd9c5 into unkeyed:main Oct 29, 2024
4 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Requires CLA Waiting for a contributor to sign the CLA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants