-
Notifications
You must be signed in to change notification settings - Fork 35
Improve node upsert performances #5966
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -432,25 +432,71 @@ def parse_schema_path(self, path: str, schema: SchemaBranch | None = None) -> Sc | |
| def get_unique_constraint_schema_attribute_paths( | ||
| self, | ||
| schema_branch: SchemaBranch, | ||
| include_unique_attributes: bool = False, | ||
| ) -> list[list[SchemaAttributePath]]: | ||
| constraint_paths_groups = [] | ||
| if include_unique_attributes: | ||
| for attribute_schema in self.unique_attributes: | ||
| constraint_paths_groups.append( | ||
| [SchemaAttributePath(attribute_schema=attribute_schema, attribute_property_name="value")] | ||
| ) | ||
|
|
||
| if not self.uniqueness_constraints: | ||
| return constraint_paths_groups | ||
| ) -> list[SchemaUniquenessConstraintPath]: | ||
| if self.uniqueness_constraints is None: | ||
| return [] | ||
|
|
||
| uniqueness_constraint_paths = [] | ||
|
|
||
| for uniqueness_path_group in self.uniqueness_constraints: | ||
| constraint_paths_group = [] | ||
| for uniqueness_path_part in uniqueness_path_group: | ||
| constraint_paths_group.append(self.parse_schema_path(path=uniqueness_path_part, schema=schema_branch)) | ||
| if constraint_paths_group not in constraint_paths_groups: | ||
| constraint_paths_groups.append(constraint_paths_group) | ||
| return constraint_paths_groups | ||
| attributes_paths = [ | ||
| self.parse_schema_path(path=uniqueness_path_part, schema=schema_branch) | ||
| for uniqueness_path_part in uniqueness_path_group | ||
| ] | ||
| uniqueness_constraint_type = self.get_uniqueness_constraint_type( | ||
| uniqueness_constraint=set(uniqueness_path_group), schema_branch=schema_branch | ||
| ) | ||
| uniqueness_constraint_path = SchemaUniquenessConstraintPath( | ||
| attributes_paths=attributes_paths, typ=uniqueness_constraint_type | ||
| ) | ||
| uniqueness_constraint_paths.append(uniqueness_constraint_path) | ||
|
|
||
| return uniqueness_constraint_paths | ||
|
|
||
| def convert_hfid_to_uniqueness_constraint(self, schema_branch: SchemaBranch) -> list[str] | None: | ||
LucasG0 marked this conversation as resolved.
Show resolved
Hide resolved
LucasG0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if self.human_friendly_id is None: | ||
| return None | ||
|
|
||
| uniqueness_constraint = [] | ||
| for item in self.human_friendly_id: | ||
| schema_attribute_path = self.parse_schema_path(path=item, schema=schema_branch) | ||
| if schema_attribute_path.is_type_attribute: | ||
| uniqueness_constraint.append(item) | ||
| elif schema_attribute_path.is_type_relationship: | ||
| uniqueness_constraint.append(schema_attribute_path.relationship_schema.name) | ||
| return uniqueness_constraint | ||
|
|
||
| def get_uniqueness_constraint_type( | ||
| self, uniqueness_constraint: set[str], schema_branch: SchemaBranch | ||
| ) -> UniquenessConstraintType: | ||
| hfid = self.convert_hfid_to_uniqueness_constraint(schema_branch=schema_branch) | ||
| if hfid is None: | ||
| return UniquenessConstraintType.STANDARD | ||
| hfid_set = set(hfid) | ||
| if uniqueness_constraint == hfid_set: | ||
| return UniquenessConstraintType.HFID | ||
| if uniqueness_constraint <= hfid_set: | ||
| return UniquenessConstraintType.SUBSET_OF_HFID | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would have thought this was not possible. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, but nothing prevents from having another uniqueness constraint that is a subset of the hfid. For instance the schema |
||
| return UniquenessConstraintType.STANDARD | ||
|
|
||
|
|
||
| @dataclass | ||
| class SchemaUniquenessConstraintPath: | ||
| attributes_paths: list[SchemaAttributePath] | ||
| typ: UniquenessConstraintType | ||
|
|
||
|
|
||
| class UniquenessConstraintType(Enum): | ||
| HFID = "HFID" | ||
| SUBSET_OF_HFID = "SUBSET_OF_HFID" | ||
| STANDARD = "STANDARD" | ||
|
|
||
|
|
||
| @dataclass | ||
| class UniquenessConstraintViolation: | ||
| nodes_ids: set[str] | ||
| fields: list[str] | ||
| typ: UniquenessConstraintType | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is out of scope for this PR, but it would be more SOLID to move all of this logic for uniqueness constraints and parsing schema paths into their own separate module(s) instead of putting it all on the |
||
|
|
||
|
|
||
| @dataclass | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would think that we generally leave migrations alone once they are merged, but not sure if others agree with that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think code imported by the migration might change as well, so migration behavior might be slightly different anyway