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

Increase item limit during plex token retrieval #85

Merged
merged 1 commit into from
Jan 29, 2024
Merged

Conversation

nylonee
Copy link
Owner

@nylonee nylonee commented Jan 29, 2024

Partial fix for #79

Summary by CodeRabbit

  • New Features
    • Integrated RSS feed support for fetching watchlist data, enhancing content synchronization.
    • Implemented pagination for Plex API requests, allowing for more efficient data retrieval by specifying subsets of items.
  • Refactor
    • Adjusted HTTP GET request parameters in test specifications to align with new pagination capabilities.

Copy link

coderabbitai bot commented Jan 29, 2024

Walkthrough

The recent modifications focus on enhancing the synchronization feature of a Scala application, specifically targeting Plex watchlist data. By integrating RSS feed data and adding pagination to the API requests, these changes aim to streamline and enrich the process of syncing watchlist content, ensuring a more efficient and tailored data retrieval from Plex servers.

Changes

Files Change Summary
.../PlexTokenDeleteSync.scala Introduced RSS feed data fetching for watchlist synchronization.
.../plex/PlexUtils.scala
.../PlexTokenSyncSpec.scala
.../plex/PlexUtilsSpec.scala
Added pagination to Plex API requests, enabling specific subsets of watchlist items to be retrieved efficiently.

🐇✨
In the digital burrow, beneath the moon's bright gaze,
A rabbit works with code, through the night's quiet phase.
Adding pages to the tale, fetching lists from afar,
Syncing watchlists with care, guided by the northern star.
🌟📚

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>.
    • Generate unit-tests for this file.
  • 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 tests 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 generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@nylonee nylonee merged commit bec6436 into main Jan 29, 2024
2 checks passed
Copy link

@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.

Review Status

Actionable comments generated: 6

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between fc9af6c and 31eaef1.
Files selected for processing (4)
  • src/main/scala/PlexTokenDeleteSync.scala (2 hunks)
  • src/main/scala/plex/PlexUtils.scala (1 hunks)
  • src/test/scala/PlexTokenSyncSpec.scala (1 hunks)
  • src/test/scala/plex/PlexUtilsSpec.scala (1 hunks)
Additional comments: 6
src/main/scala/PlexTokenDeleteSync.scala (3)
  • 1-1: The import of fetchWatchlistFromRss is correctly added to enable fetching watchlist data from RSS feeds.
  • 26-26: The aggregation of items from different sources (selfWatchlist, othersWatchlist, watchlistData) and passing them to missingIdsOnPlex is logically sound. It ensures that all relevant items are considered when determining which items are missing on Plex.
  • 1-4: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [56-56]

The deletion logic in deleteMovie and deleteSeries is dependent on configuration flags (movieDeleting, endedShowDeleting, continuingShowDeleting). This is a good practice as it allows for flexible configuration of the deletion behavior. However, ensure that these configurations are well-documented and validated at startup to prevent unintended deletions.

src/test/scala/plex/PlexUtilsSpec.scala (1)
  • 69-69: The addition of pagination parameters (X-Plex-Container-Start=0 & X-Plex-Container-Size=300) in the URI for the HTTP GET request is correctly implemented. This ensures that the test aligns with the new functionality introduced in PlexUtils.scala.
src/main/scala/plex/PlexUtils.scala (1)
  • 56-57: The addition of pagination parameters (X-Plex-Container-Start and X-Plex-Container-Size) to the Plex API request is correctly implemented. This change allows for fetching a specific subset of items from the watchlist, addressing the PR's objective to increase the item limit during Plex token retrieval.
src/test/scala/PlexTokenSyncSpec.scala (1)
  • 69-69: The update to include pagination parameters (X-Plex-Container-Start=0 & X-Plex-Container-Size=300) in the URI for the HTTP GET request within the test is correctly implemented. This ensures that the test reflects the changes made to the functionality in PlexUtils.scala.

@@ -17,10 +18,12 @@ object PlexTokenDeleteSync extends PlexUtils with SonarrUtils with RadarrUtils {
val result = for {
selfWatchlist <- getSelfWatchlist(config.plexConfiguration, client)
othersWatchlist <- if (config.plexConfiguration.skipFriendSync) EitherT.pure[IO, Throwable](Set.empty[Item]) else getOthersWatchlist(config.plexConfiguration, client)
watchlistDatas <- EitherT[IO, Throwable, List[Set[Item]]](config.plexConfiguration.plexWatchlistUrls.map(fetchWatchlistFromRss(client)).toList.sequence.map(Right(_)))
Copy link

Choose a reason for hiding this comment

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

The use of sequence on a list of IO actions to fetch watchlist data from multiple RSS feeds is a good practice for handling multiple asynchronous operations concurrently. However, consider handling potential failures for each feed individually to avoid failing the entire operation if one feed is inaccessible.

config.plexConfiguration.plexWatchlistUrls.map(url => fetchWatchlistFromRss(client)(url).attempt).toList.sequence.map(_.collect { case Right(items) => items })

Comment on lines +1 to 4
import WatchlistSync.fetchWatchlistFromRss
import cats.data.EitherT
import cats.effect.IO
import cats.implicits._
Copy link

Choose a reason for hiding this comment

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

📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [56-56]

The method missingIdsOnPlex correctly iterates over each item to check if it exists in the watchlist. However, the pattern matching inside the loop could be simplified by extracting common logic, such as the creation of EitherT[IO, Throwable, Unit] for successful checks, outside the match statement.

Consider refactoring to reduce redundancy and improve readability.


📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [56-56]

The error handling in missingIdsOnPlex uses a generic Throwable for unknown categories, which might obscure the root cause of errors. It's recommended to use more specific exceptions or to include more context in the error message.

EitherT[IO, Throwable, Unit](IO.pure(Left(new IllegalArgumentException(s"Unknown category $c for item ${item.title}"))))

@@ -66,7 +66,7 @@ class PlexUtilsSpec extends AnyFlatSpec with Matchers with PlexUtils with MockFa
val config = createConfiguration(Set("test-token"))
(mockClient.httpRequest _).expects(
Method.GET,
Uri.unsafeFromString("https://metadata.provider.plex.tv/library/sections/watchlist/all?X-Plex-Token=test-token"),
Uri.unsafeFromString("https://metadata.provider.plex.tv/library/sections/watchlist/all?X-Plex-Token=test-token&X-Plex-Container-Start=0&X-Plex-Container-Size=300"),
Copy link

Choose a reason for hiding this comment

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

While the test correctly includes the new pagination parameters, it's important to also verify the behavior when different values for these parameters are used. Consider adding tests to cover scenarios with different starting points and sizes to ensure the pagination logic works as expected across a range of values.

Suggest adding parameterized tests to cover a variety of pagination scenarios.

Comment on lines +56 to +57
.withQueryParam("X-Plex-Container-Start", 0) // todo: pagination
.withQueryParam("X-Plex-Container-Size", 300)
Copy link

Choose a reason for hiding this comment

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

While the hardcoded values for pagination (X-Plex-Container-Start=0 and X-Plex-Container-Size=300) are a good starting point, consider making these values configurable or dynamically adjustable based on the total number of items in the watchlist. This would allow for more flexibility and efficiency in data retrieval.

Suggest adding configuration options or logic to adjust pagination parameters dynamically.

@@ -66,7 +66,7 @@ class PlexTokenSyncSpec extends AnyFlatSpec with Matchers with MockFactory {
private def defaultPlexMock(httpClient: HttpClient): HttpClient = {
(httpClient.httpRequest _).expects(
Method.GET,
Uri.unsafeFromString("https://metadata.provider.plex.tv/library/sections/watchlist/all?X-Plex-Token=plex-token"),
Uri.unsafeFromString("https://metadata.provider.plex.tv/library/sections/watchlist/all?X-Plex-Token=plex-token&X-Plex-Container-Start=0&X-Plex-Container-Size=300"),
Copy link

Choose a reason for hiding this comment

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

As with the PlexUtilsSpec.scala file, consider adding tests to cover different pagination scenarios to ensure the functionality works correctly across a range of values for X-Plex-Container-Start and X-Plex-Container-Size.

Suggest adding parameterized tests to cover various pagination scenarios.

@nylonee nylonee deleted the increase-item-limit branch February 1, 2024 19:40
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.

1 participant