Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@steven-tey
Copy link
Collaborator

@steven-tey steven-tey commented Jun 3, 2025

Summary by CodeRabbit

  • Improvements
    • Links are now prioritized by most recent creation date in various bulk operations, such as deletion, transfer, and update.
    • When fetching links without a search term, results are limited to those created within the last 30 days.
  • Performance
    • Added a new database index to improve the speed of bulk link deletion by domain and creation date.
  • Other Changes
    • Internal query handling and ordering have been refined for consistency across endpoints.

@vercel
Copy link
Contributor

vercel bot commented Jun 3, 2025

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

Name Status Preview Updated (UTC)
dub ✅ Ready (Inspect) Visit Preview Jun 3, 2025 11:43pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 3, 2025

Walkthrough

The changes introduce or adjust ordering by createdAt in several database queries related to link management, add a new composite index [domain, createdAt] to the Link model, and implement rate-limiting for image deletions in a domain deletion cron job. Some reordering and filtering logic was updated, and certain domain deletion steps were commented out.

Changes

File(s) Change Summary
apps/web/app/(ee)/api/admin/links/route.ts Added a 30-day createdAt filter to link queries when search is not provided.
apps/web/app/(ee)/api/cron/domains/delete/route.ts Added ordering by createdAt, rate-limited image deletions, removed re-queue and domain/logo delete logic (commented out).
apps/web/app/(ee)/api/cron/domains/transfer/route.ts
apps/web/app/(ee)/api/cron/domains/update/route.ts
apps/web/app/(ee)/api/cron/folders/delete/route.ts
Added explicit descending orderBy: createdAt to link queries.
apps/web/app/api/domains/route.ts Reordered filter conditions in link query; logic unchanged.
packages/prisma/schema/link.prisma Added composite index [domain, createdAt] on Link model; expanded comment on existing index.

Sequence Diagram(s)

sequenceDiagram
    participant Admin as Admin API (links)
    participant DB as Database
    Admin->>DB: Query links (with/without search)
    alt search param not provided
        DB-->>Admin: Return links created in last 30 days
    else search provided
        DB-->>Admin: Return matching links (no date filter)
    end
Loading
sequenceDiagram
    participant Cron as Cron Domain Delete
    participant DB as Database
    participant R2 as R2 Storage
    participant Limiter as Rate Limiter

    Cron->>DB: Fetch links ordered by createdAt DESC
    Cron->>Limiter: Schedule image deletion for each link
    Limiter->>R2: Delete image
    Cron-->>Cron: (Domain/logo deletion logic commented out)
    Cron-->>Cron: Log number of links found
Loading

Poem

In the meadow of links, we prune and we sort,
By date and by domain, with queries quite short.
A new index appears, swift as a hare,
While images vanish with rate-limited care.
The code hops ahead, neat and precise—
A bunny’s delight, in logic concise! 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 48a233e and 5a066c5.

📒 Files selected for processing (7)
  • apps/web/app/(ee)/api/admin/links/route.ts (1 hunks)
  • apps/web/app/(ee)/api/cron/domains/delete/route.ts (4 hunks)
  • apps/web/app/(ee)/api/cron/domains/transfer/route.ts (1 hunks)
  • apps/web/app/(ee)/api/cron/domains/update/route.ts (1 hunks)
  • apps/web/app/(ee)/api/cron/folders/delete/route.ts (1 hunks)
  • apps/web/app/api/domains/route.ts (1 hunks)
  • packages/prisma/schema/link.prisma (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
apps/web/app/(ee)/api/cron/domains/delete/route.ts (2)
apps/web/lib/storage.ts (1)
  • storage (151-151)
packages/utils/src/constants/main.ts (1)
  • R2_URL (77-77)
🔇 Additional comments (10)
packages/prisma/schema/link.prisma (2)

91-91: Well-designed composite index for bulk operations.

The new [domain, createdAt] index is correctly structured with domain as the leading column for filtering and createdAt for efficient ordering in the bulk deletion workflows.


93-93: Improved documentation for existing index.

The expanded comment better documents the multiple use cases for the userId index, improving code maintainability.

apps/web/app/(ee)/api/cron/domains/update/route.ts (1)

41-43: Excellent use of the new composite index.

Adding createdAt: "desc" ordering prioritizes processing of recently created links, which improves user experience for recent domain changes. This query will efficiently leverage the new [domain, createdAt] index.

apps/web/app/api/domains/route.ts (1)

47-49: Minor query optimization through filter reordering.

Reordering the domain filter before the key filter is a good practice as domain is likely more selective than checking for just two specific key values.

apps/web/app/(ee)/api/cron/domains/transfer/route.ts (1)

32-34: LGTM! Consistent ordering for transfer operations.

The addition of orderBy: { createdAt: "desc" } ensures consistent processing order and prioritizes more recent links during transfer operations, which aligns with similar changes across other cron routes.

apps/web/app/(ee)/api/cron/domains/delete/route.ts (5)

3-3: Good addition of rate limiting capability.

Adding the limiter import enables proper rate limiting for storage operations, which is implemented well in the R2 deletion logic below.


46-49: LGTM! Consistent ordering pattern.

The addition of take: 100 and orderBy: { createdAt: "desc" } maintains consistency with other cron routes and ensures predictable processing order.


52-52: Helpful logging for monitoring.

The console log provides useful visibility into the deletion process.


68-72: Excellent rate limiting implementation for storage operations.

Using limiter.schedule() for R2 deletions prevents overwhelming the storage service and is a best practice for bulk operations.


112-131:

Details

❓ Verification inconclusive

Critical functionality is disabled - verify if intentional.

The commented-out code disables two essential features:

  1. Re-queuing domain deletion jobs when links remain (lines 112-120)
  2. Final domain and logo deletion after all links are processed (lines 122-131)

This fundamentally changes the behavior from actually deleting domains to only deleting links. The response message still claims "Domain deleted" (line 134) but the domain isn't actually removed.

Please confirm if this is intentional (e.g., for testing/debugging) or if this code should be re-enabled:


🏁 Script executed:

#!/bin/bash
# Check if there are any related tests or documentation about this change
rg -A 5 -B 5 "queueDomainDeletion|Domain deleted" --type ts

Length of output: 3636


Verify intentional removal of domain deletion and re-queuing

The cron route’s logic for

  • re-queuing remaining link batches (formerly lines 112–120) and
  • deleting the domain record and its logo (formerly lines 122–131)

is currently commented out. This means only the links are ever deleted, yet the response still claims “Domain deleted.”

Please confirm whether this change was intentional (e.g., for testing/debugging or a phased rollout). If not, you should:

  • Re-enable queueDomainDeletion when remainingLinks > 0
  • Restore the final prisma.domain.delete and storage.delete calls once all links are processed
  • Update the response message to reflect actual behavior
  • Add or update tests covering the cron deletion workflow

@steven-tey steven-tey merged commit 9504947 into main Jun 3, 2025
9 checks passed
@steven-tey steven-tey deleted the domain-createdat branch June 3, 2025 23:51
This was referenced Jul 18, 2025
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