From 457eeea6dbcd79d98c28b5fd423a9391d44fbb7b Mon Sep 17 00:00:00 2001 From: Felix Stupp Date: Sun, 2 Jul 2023 17:28:14 +0200 Subject: [PATCH] entities: UriHolder subclasses call super & avoid doubled action --- .../entertainment_decider/models/entities.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/server/entertainment_decider/models/entities.py b/server/entertainment_decider/models/entities.py index 6dcacbf..4a87957 100644 --- a/server/entertainment_decider/models/entities.py +++ b/server/entertainment_decider/models/entities.py @@ -420,6 +420,10 @@ class MediaElement(db.Entity, UriHolder, Tagable): return self.__uri def _set_primary_uri(self, uri: str) -> bool: + action = super()._set_primary_uri(uri) + if action: + # do nothing if action already applied + return True self.__uri = uri return True @@ -431,6 +435,10 @@ class MediaElement(db.Entity, UriHolder, Tagable): self.__uri_list = set() def _add_uri_to_set(self, uri: str) -> bool: + action = super()._add_uri_to_set(uri) + if action: + # do nothing if action already applied + return True mapping: Optional[MediaUriMapping] = MediaUriMapping.get(uri=uri) if not mapping: logging.debug(f"Add URI mapping {uri!r} to media {self.id!r}") @@ -446,6 +454,10 @@ class MediaElement(db.Entity, UriHolder, Tagable): return False def _remove_uri_from_set(self, uri: str) -> bool: + action = super()._remove_uri_from_set(uri) + if action: + # do nothing if action already applied + return True mapping: Optional[MediaUriMapping] = MediaUriMapping.get( uri=uri, element=self, @@ -768,6 +780,10 @@ class MediaCollection(db.Entity, UriHolder, Tagable): return self.__uri def _set_primary_uri(self, uri: str) -> bool: + action = super()._set_primary_uri(uri) + if action: + # do nothing if action already applied + return True self.__uri = uri return True @@ -779,6 +795,10 @@ class MediaCollection(db.Entity, UriHolder, Tagable): self.__uri_set = set() def _add_uri_to_set(self, uri: str) -> bool: + action = super()._add_uri_to_set(uri) + if action: + # do nothing if action already applied + return True mapping: CollectionUriMapping = CollectionUriMapping.get(uri=uri) if not mapping: logging.debug(f"Add URI mapping {uri!r} to collection {self.id!r}") @@ -794,6 +814,10 @@ class MediaCollection(db.Entity, UriHolder, Tagable): return False def _remove_uri_from_set(self, uri: str) -> bool: + action = super()._remove_uri_from_set(uri) + if action: + # do nothing if action already applied + return True mapping: Optional[CollectionUriMapping] = CollectionUriMapping.get( uri=uri, element=self,