feat: implemented push to
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
a3ef671f00
commit
312e26ec44
@ -36,6 +36,8 @@ class Collection(Generic[T]):
|
|||||||
self.append_object_to_attribute: Dict[str, T] = append_object_to_attribute or {}
|
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.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.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)
|
self._id_to_index_values: Dict[int, set] = defaultdict(set)
|
||||||
|
|
||||||
@ -79,11 +81,16 @@ class Collection(Generic[T]):
|
|||||||
self._map_element(e)
|
self._map_element(e)
|
||||||
|
|
||||||
def _find_object(self, __object: T) -> Optional[T]:
|
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()
|
self._remap()
|
||||||
|
|
||||||
for name, value in __object.indexing_values:
|
for name, value in __object.indexing_values:
|
||||||
if value in self._indexed_values[name]:
|
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):
|
def append(self, __object: Optional[T], **kwargs):
|
||||||
"""
|
"""
|
||||||
@ -98,7 +105,7 @@ class Collection(Generic[T]):
|
|||||||
if __object is None:
|
if __object is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
existing_object = self._find_object(__object)
|
existing_object, map_to = self._find_object(__object)
|
||||||
|
|
||||||
if existing_object is None:
|
if existing_object is None:
|
||||||
# append
|
# append
|
||||||
@ -133,8 +140,6 @@ class Collection(Generic[T]):
|
|||||||
synced_with.__setattr__(key, a)
|
synced_with.__setattr__(key, a)
|
||||||
a._collection_for[synced_with] = key
|
a._collection_for[synced_with] = key
|
||||||
|
|
||||||
print(synced_with, key)
|
|
||||||
|
|
||||||
a.extend(b_data, **kwargs)
|
a.extend(b_data, **kwargs)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@ -143,7 +148,7 @@ class Collection(Generic[T]):
|
|||||||
return
|
return
|
||||||
|
|
||||||
existing_object.merge(__object, **kwargs)
|
existing_object.merge(__object, **kwargs)
|
||||||
self._map_element(existing_object)
|
map_to._map_element(existing_object)
|
||||||
|
|
||||||
def contains(self, __object: T) -> bool:
|
def contains(self, __object: T) -> bool:
|
||||||
return self._find_object(__object) is not None
|
return self._find_object(__object) is not None
|
||||||
|
@ -143,6 +143,8 @@ class Song(Base):
|
|||||||
"feature_song_collection": self
|
"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]):
|
def _add_other_db_objects(self, object_type: Type[OuterProxy], object_list: List[OuterProxy]):
|
||||||
if object_type is Song:
|
if object_type is Song:
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user