fix/metal_archives #10

Merged
Elara6331 merged 15 commits from fix/metal_archives into experimental 2024-04-18 15:50:48 +00:00
2 changed files with 11 additions and 1 deletions
Showing only changes of commit 3532fea36c - Show all commits

View File

@ -36,6 +36,7 @@ class Collection(Generic[T]):
# Value: main collection to sync to
self.contain_given_in_attribute: Dict[str, Collection] = contain_given_in_attribute or {}
self.append_object_to_attribute: Dict[str, T] = append_object_to_attribute or {}
self.sync_on_append: Dict[str, Collection] = sync_on_append or {}
self._id_to_index_values: Dict[int, set] = defaultdict(set)
self._indexed_values = defaultdict(lambda: None)
@ -229,6 +230,11 @@ class Collection(Generic[T]):
for attribute, new_object in self.append_object_to_attribute.items():
__object.__getattribute__(attribute).append(new_object)
for attribute, collection in self.sync_on_append.items():
collection.extend(__object.__getattribute__(attribute))
__object.__setattr__(attribute, collection)
else:
# merge only if the two objects are not the same
if existing_object.id == __object.id:

View File

@ -91,6 +91,10 @@ class Song(Base):
"artist_collection": self.main_artist_collection,
}
"""
self.album_collection.sync_on_append = {
"artist_collection": self.main_artist_collection,
}
self.album_collection.append_object_to_attribute = {
"song_collection": self,
}
@ -247,7 +251,7 @@ class Album(Base):
self.song_collection.append_object_to_attribute = {
"album_collection": self
}
self.song_collection.contain_given_in_attribute = {
self.song_collection.sync_on_append = {
"main_artist_collection": self.artist_collection
}