Repository navigation
Backlog
Labels
type/tech-debtItem we know we need to improve way it is implemented
Description
The tracking cleanup now deletes unused members in dependency order (#1487, fixing #1477). The review of that pull request listed six changes that can be made in separate pull requests. They are collected here so they are not lost. Which of them to do, and in which order, is not decided yet.
Source: review by ogenstad on #1487, at commit 70101e03. The line links below point at that commit.
Changes to make
- Share the client-side ordering between callers. The ordering code that uses the client (
_order_for_deletionin both clients,_mandatory_peer_idsand_member_peers, query_groups.py:124-141) lives in the group context. A futureclient.delete_nodes()would have to copy it or import private helpers. One method per client that reads the schema, queries the peers and returns the order would letdelete_unusedand later callers share it. That method needs the schema refresh that_order_for_deletionnow does when a kind is missing from the cache, because a caller that did not read a group first may have an incomplete cache. - Send fewer and smaller peer query requests. The peer query at query_groups.py:291 sends every id with every page request. With 5,000 members and the default page size of 50, that is 101 requests of about 190 KB each. Splitting the ids into chunks the size of a page, or setting
limit=len(ids), avoids this. The async client also sends the query for each kind one after another. - Accept dependencies that are not keys in the graph helpers.
dependents_firstandstrongly_connected_componentsraiseKeyErrorwhen a dependency is not a key, for exampledependents_first({"a": {"b"}}, order=["a"]).topological_sortaccepts such keys. This needs fixing before the helpers are reused for import ordering. - Make
dependents_firstfaster on long chains. It runstopological_sort, which first runs a recursive cycle search and discards the result, then scans every remaining key at each level. A chain of 10,000 nodes costs about 10^8 set operations, and a long chain that contains a cycle can reach Python's recursion limit. - Use one dependency graph for deletion and import.
_mandatory_peer_kindsbuilds the same graph asInfrahubSchemaTopologicalSorter.get_sorted_node_schema(required_relationships_only=True)in transfer/schema_sorter.py, but handles generic peers differently, so a fix to one does not reach the other. - Simplify
PeerLookup.relationshipsto a list of names.DeletionOrder.cardinality_manyand thedict[str, bool]form ofPeerLookup.relationshipsexist only so_mandatory_peer_idscan choose an accessor. The node already carries its schema, sorelationshipscould be alist[str].
Not decided yet
- Whether a public API to delete many nodes in dependency order, such as
client.delete_nodes(), should be added, and what its name and behaviour would be. - Which branch these changes target.
Metadata
Metadata
Assignees
Labels
type/tech-debtItem we know we need to improve way it is implemented
Activity