Skip to content

Conversation

@avaly
Copy link

@avaly avaly commented Dec 1, 2025

Description

  • Updated the interval.seconds to 120 in the config template
  • Updated the RSS interval to be randomly selected between refreshInterval & 4 * refreshInterval
  • Removed the cache_buster parameter (has no effect anymore - prevents a 302 redirect)
  • Reduce the container size parameter to 100
  • Add random delays during pagination requests

PS: The code was edited using an AI agent. Please point out any mistakes.

Checklist

  • Documentation Updated
  • sbt scalafmtAll Run (and optionally sbt scalafmtSbt)
  • At least one approval from a codeowner

Summary by CodeRabbit

Release Notes

  • Chores
    • Increased default polling interval for Plex synchronization from 10 to 120 seconds
    • Added randomized jitter to synchronization operations for improved server stability
    • Refined data retrieval paging parameters for more conservative resource usage

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 1, 2025

Walkthrough

The PR adjusts Plex synchronization polling intervals and introduces randomized delays to reduce server load. Default polling interval increased from 10 to 120 seconds (range 60–300 seconds). Jittered sleep durations added in Server.scala and PlexUtils.scala; cache-buster UUID removed and paging size reduced from 300 to 100.

Changes

Cohort / File(s) Summary
Configuration & Defaults
src/main/resources/config-template.yaml, src/main/scala/configuration/ConfigurationUtils.scala
Updated interval configuration range from "10-30 seconds" to "60-300 seconds"; default seconds value increased from 10 to 120 seconds; ConfigurationUtils default refreshInterval changed from 60 to 120 seconds.
Plex Synchronization Timing
src/main/scala/Server.scala
Added Random import; replaced fixed sleep after PlexTokenSync with jittered sleep bounded by 3× refreshInterval; sleep duration now refreshInterval + randomMillis.
Plex API Pacing & Paging
src/main/scala/plex/PlexUtils.scala
Removed random UUID cache-buster from Plex RSS fetch; added Random and duration imports; reduced container paging size from 300 to 100 for self-watchlist retrieval; introduced random sleep of 3–13 seconds before paging calls; wrapped subsequent paging calls in for-comprehensions to incorporate delays.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • PlexUtils.scala paging and delay logic: Multiple interrelated changes (UUID removal, page size reduction, random sleep introduction, for-comprehension wrapping) require careful verification of Plex API behavior and impact.
  • Server.scala jitter implementation: Review random generation bounds and sleep calculation to ensure jitter doesn't exceed intended maximum delay.
  • Configuration cascading: Verify that configuration changes propagate correctly across ConfigurationUtils and config-template.yaml.

Possibly related PRs

Suggested reviewers

  • patriqcs
  • nylonee

Poem

🐰 A rabbit hops with gentle care,
Spacing requests through the air,
No UUID tricks to mask the way,
Just jittered delays, kind and gay,
Plex servers thank you every day! 🌟

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'fix: Update Plex requests' is vague and generic, using a broad term 'Update' that doesn't convey the specific nature of the changes (polling intervals, random delays, parameter removal). Consider a more specific title like 'fix: Increase default polling interval and add jittered delays to Plex requests' to better convey the main changes.
✅ Passed checks (2 passed)
Check name Status Explanation
Description check ✅ Passed The pull request description covers the main changes (interval update, random intervals, cache buster removal, container size reduction, pagination delays) and includes the required checklist template.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/main/scala/plex/PlexUtils.scala (2)

86-91: Consider using cats-effect Random for consistency.

This code uses scala.util.Random directly, while Server.scala uses cats.effect.std.Random.scalaUtilRandom[IO]. For consistency and referential transparency, consider aligning with the cats-effect approach:

-            for {
-              // We should be considerate with the Plex servers
-              randomSeconds <- EitherT.liftF(IO(Random.nextInt(11)))
-              _             <- EitherT.liftF(IO.sleep(3.seconds + randomSeconds.seconds))
-              next          <- getSelfWatchlist(config, client, containerStart + containerSize)
-            } yield next
+            for {
+              // We should be considerate with the Plex servers
+              rand          <- EitherT.liftF(Random.scalaUtilRandom[IO])
+              randomSeconds <- EitherT.liftF(rand.nextIntBounded(11))
+              _             <- EitherT.liftF(IO.sleep(3.seconds + randomSeconds.seconds))
+              next          <- getSelfWatchlist(config, client, containerStart + containerSize)
+            } yield next

The same applies to getWatchlistIdsForUser at lines 187-192.


187-192: Delay logic is consistent with getSelfWatchlist.

The same delay pattern is applied here, which is good for consistency. Consider extracting the delay logic into a shared helper method to reduce duplication.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bce86ec and 7fd5da8.

📒 Files selected for processing (4)
  • src/main/resources/config-template.yaml (1 hunks)
  • src/main/scala/Server.scala (2 hunks)
  • src/main/scala/configuration/ConfigurationUtils.scala (1 hunks)
  • src/main/scala/plex/PlexUtils.scala (5 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2024-06-10T19:44:23.144Z
Learnt from: nylonee
Repo: nylonee/watchlistarr PR: 57
File: src/test/scala/configuration/ConfigurationUtilsSpec.scala:121-130
Timestamp: 2024-06-10T19:44:23.144Z
Learning: The expected result for the test case that verifies the splitting of multiple RSS watchlist feeds is based on the mock HTTP client's response, which may contain a single `RSSInfo` object, rather than directly using the `plexWatchlists` configuration provided. This understanding is crucial for accurately assessing the expected outcomes in test cases.

Applied to files:

  • src/main/scala/plex/PlexUtils.scala
🧬 Code graph analysis (2)
src/main/scala/configuration/ConfigurationUtils.scala (2)
src/main/scala/configuration/FileAndSystemPropertyReader.scala (1)
  • getConfigOption (52-58)
src/main/scala/configuration/SystemPropertyReader.scala (1)
  • getConfigOption (4-4)
src/main/scala/Server.scala (3)
src/main/scala/PlexTokenSync.scala (2)
  • PlexTokenSync (12-99)
  • run (16-57)
src/main/scala/PlexTokenDeleteSync.scala (1)
  • run (16-47)
src/main/scala/PingTokenSync.scala (1)
  • run (7-7)
🔇 Additional comments (5)
src/main/resources/config-template.yaml (1)

5-8: LGTM!

The updated interval range (60-300 seconds) and default value (120 seconds) are consistent and align with the PR objective to be more considerate with Plex servers.

src/main/scala/configuration/ConfigurationUtils.scala (1)

31-31: LGTM!

The default interval of 120 seconds is consistent with the config template update.

src/main/scala/plex/PlexUtils.scala (2)

73-73: LGTM!

Reducing the container size to 100 combined with the pagination delays should be more considerate to Plex servers.


5-5: Verify if parSequenceN import is used.

The parSequenceN import on line 5 doesn't appear in the visible code. Confirm whether this was added intentionally for future use or should be removed.

src/main/scala/Server.scala (1)

52-57: LGTM - jittered sleep correctly implements the PR objective.

The sleep duration ranges from refreshInterval to 4 * refreshInterval as specified. With the default 120-second interval, this means 2-8 minutes between RSS syncs.

One minor optimization: Random.scalaUtilRandom[IO] creates a new Random instance on each iteration. Consider caching it, though the overhead is negligible for this use case.

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