From e9b1a12aa1a347dc0c8bc7b07909361b98d1e36e Mon Sep 17 00:00:00 2001 From: Hellow <74311245+HeIIow2@users.noreply.github.com> Date: Mon, 29 Apr 2024 23:40:48 +0200 Subject: [PATCH] draft: the problem is in _list_renderer.py --- music_kraken/objects/collection.py | 22 ++++++++++---- music_kraken/objects/parents.py | 1 + music_kraken/pages/abstract.py | 46 ------------------------------ 3 files changed, 18 insertions(+), 51 deletions(-) diff --git a/music_kraken/objects/collection.py b/music_kraken/objects/collection.py index 6f8be7e..f3139cd 100644 --- a/music_kraken/objects/collection.py +++ b/music_kraken/objects/collection.py @@ -1,7 +1,7 @@ from __future__ import annotations from collections import defaultdict -from typing import TypeVar, Generic, Dict, Optional, Iterable, List, Iterator, Tuple, Generator, Union, Any +from typing import TypeVar, Generic, Dict, Optional, Iterable, List, Iterator, Tuple, Generator, Union, Any, Set from .parents import OuterProxy from ..utils import object_trace @@ -117,14 +117,26 @@ class Collection(Generic[T]): if a is b: continue - object_trace(f"Syncing [{a}] = [{b}]") + no_sync_collection: Set[Collection] = kwargs.get("no_sync_collection", set()) + object_trace(f"Syncing [{a}] = [{b}]; {no_sync_collection}") + if id(b) in no_sync_collection: + continue - for synced_with, key in b._collection_for.items(): + + b_data = b.data.copy() + b_collection_for = b._collection_for.copy() + no_sync_collection.add(id(b)) + kwargs["no_sync_collection"] = no_sync_collection + del b + + for synced_with, key in b_collection_for.items(): synced_with.__setattr__(key, a) - a._collection_for.update(b._collection_for) + a._collection_for[synced_with] = key - a.extend(b.data, **kwargs) + print(synced_with, key) + a.extend(b_data, **kwargs) + else: # merge only if the two objects are not the same if existing_object.id == __object.id: diff --git a/music_kraken/objects/parents.py b/music_kraken/objects/parents.py index c6f2138..c0669c0 100644 --- a/music_kraken/objects/parents.py +++ b/music_kraken/objects/parents.py @@ -45,6 +45,7 @@ class InnerData: for key, value in kwargs.items(): if hasattr(value, "__is_collection__"): value._collection_for[self] = key + self.__setattr__(key, value) def __hash__(self): diff --git a/music_kraken/pages/abstract.py b/music_kraken/pages/abstract.py index c405c60..0ea15db 100644 --- a/music_kraken/pages/abstract.py +++ b/music_kraken/pages/abstract.py @@ -89,52 +89,6 @@ class NamingDict(dict): return self.default_value_for_name(attribute_name) -def _clean_music_object(music_object: INDEPENDENT_DB_OBJECTS, collections: Dict[INDEPENDENT_DB_TYPES, Collection]): - if type(music_object) == Label: - return _clean_label(label=music_object, collections=collections) - if type(music_object) == Artist: - return _clean_artist(artist=music_object, collections=collections) - if type(music_object) == Album: - return _clean_album(album=music_object, collections=collections) - if type(music_object) == Song: - return _clean_song(song=music_object, collections=collections) - - -def _clean_collection(collection: Collection, collection_dict: Dict[INDEPENDENT_DB_TYPES, Collection]): - if collection.element_type not in collection_dict: - return - - for i, element in enumerate(collection): - r = collection_dict[collection.element_type].append(element, merge_into_existing=True) - collection[i] = r.current_element - - if not r.was_the_same: - _clean_music_object(r.current_element, collection_dict) - - -def _clean_label(label: Label, collections: Dict[INDEPENDENT_DB_TYPES, Collection]): - _clean_collection(label.current_artist_collection, collections) - _clean_collection(label.album_collection, collections) - - -def _clean_artist(artist: Artist, collections: Dict[INDEPENDENT_DB_TYPES, Collection]): - _clean_collection(artist.main_album_collection, collections) - _clean_collection(artist.feature_song_collection, collections) - _clean_collection(artist.label_collection, collections) - - -def _clean_album(album: Album, collections: Dict[INDEPENDENT_DB_TYPES, Collection]): - _clean_collection(album.label_collection, collections) - _clean_collection(album.song_collection, collections) - _clean_collection(album.artist_collection, collections) - - -def _clean_song(song: Song, collections: Dict[INDEPENDENT_DB_TYPES, Collection]): - _clean_collection(song.album_collection, collections) - _clean_collection(song.feature_artist_collection, collections) - _clean_collection(song.main_artist_collection, collections) - - class Page: """ This is an abstract class, laying out the