From e8a90c028c078f93dd535cfd36ca7d5bdc12c004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Sun, 17 Mar 2024 18:52:41 +0200 Subject: [PATCH 1/6] Add match_headers=["X-Plex-Container-Start"] for Plex --- plextraktsync/factory/Factory.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plextraktsync/factory/Factory.py b/plextraktsync/factory/Factory.py index 1df3e712538..d95692ccea1 100644 --- a/plextraktsync/factory/Factory.py +++ b/plextraktsync/factory/Factory.py @@ -139,6 +139,8 @@ def session(self): cache_name=self.config.cache_path, cache_control=True, urls_expire_after=self.urls_expire_after, + # Plex doesn't Send Vary: X-Plex-Container-Start + match_headers=["X-Plex-Container-Start"], ) @cached_property From 467333c8d5b9efef0c2f597d314175d645876d5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Sun, 17 Mar 2024 19:50:42 +0200 Subject: [PATCH 2/6] Add cache for plex server root request --- plextraktsync/config/HttpCacheConfig.py | 3 ++- plextraktsync/plex/PlexServerConnection.py | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/plextraktsync/config/HttpCacheConfig.py b/plextraktsync/config/HttpCacheConfig.py index 6f81f64d797..00cdd70266a 100644 --- a/plextraktsync/config/HttpCacheConfig.py +++ b/plextraktsync/config/HttpCacheConfig.py @@ -109,8 +109,9 @@ class HttpCacheConfig: "*/devices": DO_NOT_CACHE, # system_account "*/accounts": DO_NOT_CACHE, + # Plex server root # version, updated_at - # "*/": DO_NOT_CACHE, + "*/": "10m", } @property diff --git a/plextraktsync/plex/PlexServerConnection.py b/plextraktsync/plex/PlexServerConnection.py index 0293accf4d4..566c93f148a 100644 --- a/plextraktsync/plex/PlexServerConnection.py +++ b/plextraktsync/plex/PlexServerConnection.py @@ -7,7 +7,6 @@ from requests.exceptions import ConnectionError, SSLError from plextraktsync.config import PLEX_PLATFORM -from plextraktsync.decorators.nocache import nocache from plextraktsync.factory import Factory, logging @@ -29,7 +28,6 @@ def config(self): def session(self): return self.factory.session - @nocache def connect(self, urls: list[str], token: str): plexapi.X_PLEX_PLATFORM = PLEX_PLATFORM plexapi.TIMEOUT = self.timeout From 77584b02cdc4348d4fe62ea8ebb7c3a6a5ee0ad9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Sun, 17 Mar 2024 20:00:20 +0200 Subject: [PATCH 3/6] Disable cache-control to be able to use our cache rules --- plextraktsync/factory/Factory.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plextraktsync/factory/Factory.py b/plextraktsync/factory/Factory.py index d95692ccea1..10bd6e8df53 100644 --- a/plextraktsync/factory/Factory.py +++ b/plextraktsync/factory/Factory.py @@ -137,7 +137,8 @@ def session(self): return CachedSession( cache_name=self.config.cache_path, - cache_control=True, + # Plex sends "Cache-Control: no-cache" headers to requests we want to cache + cache_control=False, urls_expire_after=self.urls_expire_after, # Plex doesn't Send Vary: X-Plex-Container-Start match_headers=["X-Plex-Container-Start"], From c5dd574aba345a36f3ba8a0d92203256d80972d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Sun, 17 Mar 2024 19:59:12 +0200 Subject: [PATCH 4/6] Tune http cache rules. Increase caching --- plextraktsync/config/HttpCacheConfig.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/plextraktsync/config/HttpCacheConfig.py b/plextraktsync/config/HttpCacheConfig.py index 00cdd70266a..a9a204bfb9c 100644 --- a/plextraktsync/config/HttpCacheConfig.py +++ b/plextraktsync/config/HttpCacheConfig.py @@ -34,7 +34,7 @@ class HttpCacheConfig: "api.trakt.tv/shows/*/seasons?extended=episodes": 28800, "api.trakt.tv/shows/*/seasons": DO_NOT_CACHE, "api.trakt.tv/sync/collection/shows": "1m", - "api.trakt.tv/users/*/collection/movies?extended=metadata": "1m", + "api.trakt.tv/users/*/collection/movies?extended=metadata": "10s", "api.trakt.tv/users/*/collection/movies": DO_NOT_CACHE, "api.trakt.tv/users/*/collection/shows": "1m", "api.trakt.tv/users/*/ratings/episodes": "1m", @@ -55,10 +55,10 @@ class HttpCacheConfig: # Watchlist better be fresh for next run "api.trakt.tv/users/*/watchlist/movies": "1s", "api.trakt.tv/users/*/watchlist/shows": "1s", - "metadata.provider.plex.tv/library/sections/watchlist/all?*includeUserState=0": "1s", - "metadata.provider.plex.tv/library/sections/watchlist/all": "1s", - "api.trakt.tv/users/likes/lists": DO_NOT_CACHE, - "api.trakt.tv/users/me": DO_NOT_CACHE, + "metadata.provider.plex.tv/library/sections/watchlist/all?*includeUserState=0": "60m", + "metadata.provider.plex.tv/library/sections/watchlist/all": "10m", + "api.trakt.tv/users/likes/lists": "5m", + "api.trakt.tv/users/me": "60m", # Public Lists "api.trakt.tv/lists/*": "1d", # Online Plex patterns @@ -73,25 +73,26 @@ class HttpCacheConfig: # Plex account # Cache for some time, this activates 304 responses "plex.tv/users/account": "1m", - "plex.tv/api/v2/user": "1m", + "plex.tv/api/v2/user": "15m", # Plex patterns # Ratings search - "*/library/sections/*/all?*userRating%3E%3E=-1*": "1m", + "*/library/sections/*/all?*userRating*=-1*": "5m", # len(PlexLibrarySection) - "*/library/sections/*/all?includeCollections=0&X-Plex-Container-Size=0&X-Plex-Container-Start=0": DO_NOT_CACHE, + "*/library/sections/*/all?*X-Plex-Container-Size=0": DO_NOT_CACHE, # __iter__(PlexLibrarySection) "*/library/sections/*/all?includeGuids=1": DO_NOT_CACHE, # find_by_title "*/library/sections/*/all?includeGuids=1&title=*": DO_NOT_CACHE, + # episodes + "*/library/sections/*/all?includeGuids=1&type=4*": DO_NOT_CACHE, # fetch_item, fetch_items "*/library/sections/*/all?*": DO_NOT_CACHE, + "*/library/sections/*/collections?*X-Plex-Container-Size=0": DO_NOT_CACHE, "*/library/sections/*/collections": DO_NOT_CACHE, # library_sections "*/library/sections": DO_NOT_CACHE, # reloads "*/library/metadata/*?*include*": DO_NOT_CACHE, - # episodes - "*/library/sections/*/all?includeGuids=1&type=4*": DO_NOT_CACHE, # find_by_id "*/library/metadata/*": DO_NOT_CACHE, # mark played, mark unplayed From 1a32b0012a98b717fd8dcddd498355e02a576c9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Sun, 29 Dec 2024 15:15:32 +0200 Subject: [PATCH 5/6] Reduce ratings cache to 10s --- plextraktsync/config/HttpCacheConfig.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plextraktsync/config/HttpCacheConfig.py b/plextraktsync/config/HttpCacheConfig.py index a9a204bfb9c..daf538e7ba9 100644 --- a/plextraktsync/config/HttpCacheConfig.py +++ b/plextraktsync/config/HttpCacheConfig.py @@ -37,9 +37,9 @@ class HttpCacheConfig: "api.trakt.tv/users/*/collection/movies?extended=metadata": "10s", "api.trakt.tv/users/*/collection/movies": DO_NOT_CACHE, "api.trakt.tv/users/*/collection/shows": "1m", - "api.trakt.tv/users/*/ratings/episodes": "1m", - "api.trakt.tv/users/*/ratings/shows": "1m", - "api.trakt.tv/users/*/ratings/movies": "1m", + "api.trakt.tv/users/*/ratings/episodes": "10s", + "api.trakt.tv/users/*/ratings/shows": "10s", + "api.trakt.tv/users/*/ratings/movies": "10s", # Trakt search urls "api.trakt.tv/search/imdb/tt*?type=movie": "1d", "api.trakt.tv/search/imdb/tt*?type=show": "1d", From c507f90c437b46d86a6fd4def5feaf0771dd54f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 1 Jan 2025 19:55:27 +0200 Subject: [PATCH 6/6] Lower plex ratings cache --- plextraktsync/config/HttpCacheConfig.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plextraktsync/config/HttpCacheConfig.py b/plextraktsync/config/HttpCacheConfig.py index daf538e7ba9..07a73c74b1d 100644 --- a/plextraktsync/config/HttpCacheConfig.py +++ b/plextraktsync/config/HttpCacheConfig.py @@ -76,7 +76,7 @@ class HttpCacheConfig: "plex.tv/api/v2/user": "15m", # Plex patterns # Ratings search - "*/library/sections/*/all?*userRating*=-1*": "5m", + "*/library/sections/*/all?*userRating*=-1*": "10s", # len(PlexLibrarySection) "*/library/sections/*/all?*X-Plex-Container-Size=0": DO_NOT_CACHE, # __iter__(PlexLibrarySection)