feat: changed syncing from event based to reference
This commit is contained in:
parent
86e985acec
commit
e87075a809
@ -162,6 +162,25 @@ class Collection(Generic[T]):
|
||||
|
||||
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
|
||||
for c in self.push_to:
|
||||
r = c._find_object(other)
|
||||
|
@ -148,7 +148,7 @@ class Song(Base):
|
||||
self.feature_artist_collection.push_to = [self.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,
|
||||
}
|
||||
|
||||
@ -310,7 +310,7 @@ class Album(Base):
|
||||
self.song_collection.append_object_to_attribute = {
|
||||
"album_collection": self
|
||||
}
|
||||
self.song_collection.extend_object_to_attribute = {
|
||||
self.song_collection.sync_on_append = {
|
||||
"artist_collection": self.artist_collection
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user