feat: implemented push to
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Hellow 2024-04-30 08:11:10 +02:00
parent a3ef671f00
commit 312e26ec44
2 changed files with 12 additions and 5 deletions

View File

@ -36,6 +36,8 @@ class Collection(Generic[T]):
self.append_object_to_attribute: Dict[str, T] = append_object_to_attribute or {}
self.extend_object_to_attribute: Dict[str, Collection[T]] = extend_object_to_attribute or {}
self.sync_on_append: Dict[str, Collection] = sync_on_append or {}
self.pull_from: List[Collection] = []
self.push_to: List[Collection] = []
self._id_to_index_values: Dict[int, set] = defaultdict(set)
@ -79,11 +81,16 @@ class Collection(Generic[T]):
self._map_element(e)
def _find_object(self, __object: T) -> Optional[T]:
for c in self.push_to:
found = c._find_object(__object)
if found is not None:
return found, c
self._remap()
for name, value in __object.indexing_values:
if value in self._indexed_values[name]:
return self._indexed_values[name][value]
return self._indexed_values[name][value], self
def append(self, __object: Optional[T], **kwargs):
"""
@ -98,7 +105,7 @@ class Collection(Generic[T]):
if __object is None:
return
existing_object = self._find_object(__object)
existing_object, map_to = self._find_object(__object)
if existing_object is None:
# append
@ -133,8 +140,6 @@ class Collection(Generic[T]):
synced_with.__setattr__(key, a)
a._collection_for[synced_with] = key
print(synced_with, key)
a.extend(b_data, **kwargs)
else:
@ -143,7 +148,7 @@ class Collection(Generic[T]):
return
existing_object.merge(__object, **kwargs)
self._map_element(existing_object)
map_to._map_element(existing_object)
def contains(self, __object: T) -> bool:
return self._find_object(__object) is not None

View File

@ -143,6 +143,8 @@ class Song(Base):
"feature_song_collection": self
}
self.feature_artist_collection.push_to = [self.main_artist_collection]
def _add_other_db_objects(self, object_type: Type[OuterProxy], object_list: List[OuterProxy]):
if object_type is Song:
return