Skip to content

Commit

Permalink
Use asyncio.gather for sync tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
glensc committed Apr 13, 2024
1 parent e18f73e commit 33080a8
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions plextraktsync/sync.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import asyncio
from functools import cached_property
from typing import TYPE_CHECKING

Expand Down Expand Up @@ -63,9 +64,11 @@ async def sync(self, walker: Walker, dry_run=False):
if self.config.need_library_walk:
movie_trakt_ids = set()
async for movie in walker.find_movies():
await self.sync_collection(movie, dry_run=dry_run)
await self.sync_ratings(movie, dry_run=dry_run)
await self.sync_watched(movie, dry_run=dry_run)
await asyncio.gather(*[
self.sync_collection(movie, dry_run=dry_run),
self.sync_ratings(movie, dry_run=dry_run),
self.sync_watched(movie, dry_run=dry_run),
])
if not is_partial:
listutil.addPlexItemToLists(movie)
if self.config.clear_collected:
Expand All @@ -77,9 +80,11 @@ async def sync(self, walker: Walker, dry_run=False):
shows = set()
episode_trakt_ids = set()
async for episode in walker.find_episodes():
await self.sync_collection(episode, dry_run=dry_run)
await self.sync_ratings(episode, dry_run=dry_run)
await self.sync_watched(episode, dry_run=dry_run)
await asyncio.gather(*[
self.sync_collection(episode, dry_run=dry_run),
self.sync_ratings(episode, dry_run=dry_run),
self.sync_watched(episode, dry_run=dry_run),
])
if not is_partial:
listutil.addPlexItemToLists(episode)
if self.config.clear_collected:
Expand Down

0 comments on commit 33080a8

Please sign in to comment.