Skip to content

Commit

Permalink
Merge pull request #5476 from opsmill/lgu-boost-attribute-add
Browse files Browse the repository at this point in the history
Improve performances of AttributeAddQuery
  • Loading branch information
LucasG0 authored Jan 15, 2025
2 parents d1a8bac + c0895dd commit 971fce8
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions backend/infrahub/core/migrations/query/attribute_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ async def query_init(self, db: InfrahubDatabase, **kwargs: dict[str, Any]) -> No
self.params["is_visible_default"] = True

query = """
MERGE (av:AttributeValue { value: $attr_value, is_default: true })
MERGE (is_protected_value:Boolean { value: $is_protected_default })
MERGE (is_visible_value:Boolean { value: $is_visible_default })
WITH av, is_protected_value, is_visible_value
MATCH p = (n:%(node_kind)s)
CALL {
WITH n
Expand All @@ -66,12 +70,8 @@ async def query_init(self, db: InfrahubDatabase, **kwargs: dict[str, Any]) -> No
ORDER BY r2.branch_level DESC, r2.from ASC, r1.branch_level DESC, r1.from ASC
LIMIT 1
}
WITH n1 as n, r11 as r1, r12 as r2
WITH n1 as n, r11 as r1, r12 as r2, av, is_protected_value, is_visible_value
WHERE r1.status = "active" AND (r2 IS NULL OR r2.status = "deleted")
MERGE (av:AttributeValue { value: $attr_value, is_default: true })
MERGE (is_protected_value:Boolean { value: $is_protected_default })
MERGE (is_visible_value:Boolean { value: $is_visible_default })
WITH n, av, is_protected_value, is_visible_value, r2
CREATE (a:Attribute { name: $attr_name, branch_support: $branch_support })
CREATE (n)-[:HAS_ATTRIBUTE $rel_props ]->(a)
CREATE (a)-[:HAS_VALUE $rel_props ]->(av)
Expand Down

0 comments on commit 971fce8

Please sign in to comment.