feat: changed syncing from event based to reference
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful

This commit is contained in:
Hazel 2024-05-16 17:39:12 +02:00
parent 86e985acec
commit e87075a809
2 changed files with 21 additions and 2 deletions

View File

@ -162,6 +162,25 @@ class Collection(Generic[T]):
object_trace(f"Appending {other.option_string} to {self}") object_trace(f"Appending {other.option_string} to {self}")
for attribute, a in self.sync_on_append.items():
# syncing two collections by reference
b = other.__getattribute__(attribute)
if a is b:
continue
object_trace(f"Syncing [{a}] = [{b}]")
b_data = b.data.copy()
b_collection_for = b._collection_for.copy()
del b
for synced_with, key in b_collection_for.items():
synced_with.__setattr__(key, a)
a._collection_for[synced_with] = key
a.extend(b_data, **kwargs)
# switching collection in the case of push to # switching collection in the case of push to
for c in self.push_to: for c in self.push_to:
r = c._find_object(other) r = c._find_object(other)

View File

@ -148,7 +148,7 @@ class Song(Base):
self.feature_artist_collection.push_to = [self.artist_collection] self.feature_artist_collection.push_to = [self.artist_collection]
self.artist_collection.pull_from = [self.feature_artist_collection] self.artist_collection.pull_from = [self.feature_artist_collection]
self.album_collection.extend_object_to_attribute = { self.album_collection.sync_on_append = {
"artist_collection": self.artist_collection, "artist_collection": self.artist_collection,
} }
@ -310,7 +310,7 @@ class Album(Base):
self.song_collection.append_object_to_attribute = { self.song_collection.append_object_to_attribute = {
"album_collection": self "album_collection": self
} }
self.song_collection.extend_object_to_attribute = { self.song_collection.sync_on_append = {
"artist_collection": self.artist_collection "artist_collection": self.artist_collection
} }