models: MediaCollection: Increase effiency of completed property

master
Felix Stupp 3 years ago
parent b41ecfb080
commit 629e125838
Signed by: zocker
GPG Key ID: 93E1BD26F6B02FB7

@ -460,18 +460,22 @@ class MediaCollection(db.Entity, Tagable):
def was_extracted(self) -> bool: def was_extracted(self) -> bool:
return self.last_updated is not None return self.last_updated is not None
def __to_watch_episodes(self) -> Iterable[MediaCollectionLink]:
return orm.select(link for link in self.media_links if not link.element.watched and not link.element.ignored)
@property @property
def next_episode(self) -> Optional[MediaCollectionLink]: def next_episode(self) -> Optional[MediaCollectionLink]:
#return orm \ #return orm \
# .select(link for link in self.media_links if not link.element.watched) \ # .select(link for link in self.media_links if not link.element.watched) \
# .order_by(*MediaCollectionLink.natural_order) \ # .order_by(*MediaCollectionLink.natural_order) \
# .first() # .first()
episodes = MediaCollectionLink.sorted(orm.select(link for link in self.media_links if not link.element.watched and not link.element.ignored)) episodes = MediaCollectionLink.sorted(self.__to_watch_episodes())
return episodes[0] if len(episodes) > 0 else None return episodes[0] if len(episodes) > 0 else None
@property @property
def completed(self) -> bool: def completed(self) -> bool:
return self.next_episode is None l = list(self.__to_watch_episodes())
return len(l) <= 0
@property @property
def assigned_tags(self) -> Set[Tag]: def assigned_tags(self) -> Set[Tag]:

Loading…
Cancel
Save