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: update instance availability logic for the scrape endpoint #1023

Merged
merged 1 commit into from
Mar 7, 2025

Conversation

dreulavelle
Copy link
Member

@dreulavelle dreulavelle commented Mar 7, 2025

Pull Request Check List

Resolves: #issue-number-here

  • Added tests for changed code.
  • Updated documentation for changed code.

Description:

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced error messaging for unavailable streams, so users now receive immediate feedback when a stream cannot be served.
  • Refactor
    • Updated stream availability checks and streamlined response data handling for improved reliability.

Copy link
Contributor

coderabbitai bot commented Mar 7, 2025

Walkthrough

The changes update stream caching and error handling in the scraping logic. In the scrape_item function, the caching check is bypassed by directly setting stream.is_cached to False. In the get_info_hash function, an additional check now verifies if the retrieved container exists and is cached; if not, an HTTP 400 error is raised. The response format is simplified by returning the container directly instead of wrapping it in a list.

Changes

File Change Summary
src/routers/.../scrape.py - In scrape_item, caching is now disabled by setting stream.is_cached to False instead of using downloader.get_instant_availability.
- In get_info_hash, a check is added to raise an HTTP 400 error if the container is missing or not cached, and the container is returned directly rather than as a list.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant get_info_hash
    participant Downloader
    Client->>get_info_hash: Request torrent info
    get_info_hash->>Downloader: Call get_instant_availability()
    alt Container missing or not cached
        Downloader-->>get_info_hash: Invalid container
        get_info_hash->>Client: Raise HTTPException (400)
    else Container valid
        Downloader-->>get_info_hash: Return container
        get_info_hash->>Client: Return container directly
    end
Loading
sequenceDiagram
    participant Scrape_Item
    participant Stream
    Scrape_Item->>Stream: Set is_cached = False
Loading

Poem

I'm a happy little rabbit,
Hopping through the code with a skip,
Disabling cached streams, so spry and neat,
New checks and flows make my heart beat,
Snuggle in clean logic, where bugs take a trip!
🐇💻


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0f22105 and ea3b81b.

📒 Files selected for processing (1)
  • src/routers/secure/scrape.py (3 hunks)
🔇 Additional comments (4)
src/routers/secure/scrape.py (4)

283-287: Added strict validation for cached torrents

This change adds proper validation to ensure only cached torrents can be used in the scraping session. This is a good defensive check that improves user experience by failing early with a clear message.

The error message is clear and actionable, guiding the user to try another stream when a torrent isn't cached.


226-287:

❓ Verification inconclusive

Inconsistent caching behavior across endpoints

There's an inconsistency between how caching is handled in different functions. In scrape_item, cache checks are bypassed, while in start_manual_session, cached availability is strictly enforced.

This inconsistency might be intentional based on different endpoint purposes, but it could cause confusion. Consider documenting the different behaviors in the function docstrings or aligning the caching behavior if they should be consistent.


🏁 Script executed:

#!/bin/bash
# Check which endpoints are being called by frontend code

# Find frontend API requests to both endpoints
rg "scrape/" --context=3 --glob="*.{js,ts,jsx,tsx}"

Length of output: 200


Action Required: Clarify Inconsistent Caching Behavior Between Endpoints

  • In the scrape_item routine, caching is bypassed by forcing stream.is_cached to False, while the start_manual_session endpoint performs an actual cache check via downloader.get_instant_availability and raises an error if the stream isn’t cached.
  • It’s unclear whether this discrepancy is intentional or an oversight. If the difference is by design, please add documentation in the respective function docstrings to explain why caching is handled differently. Otherwise, consider unifying the caching behavior to avoid future confusion.
  • Note: An initial attempt to trace API references in the frontend using rg returned no results. Manual verification of endpoint usage in the broader codebase or associated frontend services is advised.

226-228:

❓ Verification inconclusive

Verify the impact of disabling stream cache checking

The code now hardcodes stream.is_cached = False instead of checking actual cache status through the downloader service. This will affect the user experience by reporting all streams as uncached.

Is this intentional behavior? If so, consider adding a comment explaining why cache checking is bypassed here but still used later in the start_manual_session function. If temporary, consider adding a TODO comment.


🏁 Script executed:

#!/bin/bash
# Check for other usages of is_cached property to understand potential impacts

# Find where stream.is_cached is used in the codebase
rg "stream.is_cached" -A 3 -B 3
rg "is_cached" --context=3 --glob="*.py" | grep -v "scrape.py"

Length of output: 673


Attention: Clarify the Intentional Bypass of Cache Checking

The code in src/routers/secure/scrape.py now hardcodes stream.is_cached = False, effectively bypassing the cache status check originally performed by the downloader. Our search confirms that this change is localized to this file, but there's an indication (via the reference to start_manual_session) that cache checking might still be relevant in other parts of the codebase.

  • Action Items:
    • Confirm whether bypassing the cache check here is an intentional behavior.
    • If intentional, please add an inline comment explaining why cache checking is skipped in this context while it appears to be used later (e.g., in the start_manual_session function).
    • If this change is temporary, consider adding a TODO comment to revisit this decision.

303-303:

❓ Verification inconclusive

Changed API response format

The response format has changed from potentially wrapping the container in a list to returning it directly. This could break clients expecting the previous format.


🏁 Script executed:

#!/bin/bash
# Check for API clients using this endpoint

# Find where the StartSessionResponse is used/consumed
rg "StartSessionResponse" --context=5
rg "start_manual_session" --context=5 --glob="*.py" | grep -v "scrape.py"

# Check any frontend code that might be parsing this response
rg "containers" --context=5 --glob="*.{js,ts,jsx,tsx}"

Length of output: 2271


Action Required: Verify API Response Changes in Client Consumption

The change on line 303 of src/routers/secure/scrape.py switches the "containers" field to return the container directly instead of wrapping it in a list. Our automated search in the Python codebase shows that references to StartSessionResponse and start_manual_session are confined to this module, and no additional client usage was detected. However, the frontend search for the "containers" property did not yield any files (likely due to a glob filter issue), so we couldn’t conclusively determine if any client code expects the previous list-wrapped format.

  • Action points:
    • Manually verify that any API clients—especially frontend components—are updated or tolerant of this change.
    • Ensure that tests (if available) cover scenarios where the old response format might be assumed.
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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 generate docstrings to generate docstrings for 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.

@dreulavelle dreulavelle merged commit 486bbff into main Mar 7, 2025
2 checks passed
@dreulavelle dreulavelle deleted the bugfix/manual-scraping-cache-availability branch March 7, 2025 06:30
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