Skip to content
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

Speedups #54

Merged
merged 2 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages=["ragdaemon"]

[project]
name = "ragdaemon"
version = "0.7.7"
version = "0.7.8"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version number has been updated from 0.7.7 to 0.7.8. Please ensure that all related documentation and dependency requirements are also updated accordingly if needed.

description = "Generate and render a call graph for a Python project."
readme = "README.md"
dependencies = [
Expand Down Expand Up @@ -47,4 +47,4 @@ dev = [
]

[tool.pyright]
ignore = ["tests/sample"]
ignore = ["tests/sample"]
2 changes: 1 addition & 1 deletion ragdaemon/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.7.7"
__version__ = "0.7.8"
41 changes: 18 additions & 23 deletions ragdaemon/annotators/hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,37 +66,32 @@ async def annotate(
for parent in path.parents:
if len(parent.parts) == 0:
parent = Path("ROOT")
directories.add(parent)
directories.add(parent.as_posix())
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conversion of parent to parent.as_posix() directly in the directories set is a good change for consistency, ensuring that all directory paths are stored in the same string format.

edges.add((parent.as_posix(), _last.as_posix()))
_last = parent

for dir in directories:
dir_str = dir.as_posix()
dir_path = dir if dir != Path("ROOT") else Path(".")
document = get_document(
dir_str, cwd, type="directory", ignore_patterns=self.ignore_patterns
)
checksum = hash_str(
"".join(
checksums.get(dir_path / subpath, "")
for subpath in document.split("\n")[1:]
)
)
for source, target in edges:
for id in (source, target):
if id not in graph and id not in directories:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check for id not being in graph or directories before adding an edge is crucial for data integrity. This prevents the graph from having edges that reference non-existent nodes.

raise RagdaemonError(f"Node {id} not found in graph")
graph.add_edge(source, target, type="hierarchy")

# Fill-in directory data (same process as get_document for dirs, but more efficient)
for dir in sorted(
Comment on lines +79 to +80
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Fill-in directory data (same process as get_document for dirs, but more efficient)
for dir in sorted(
for dir in sorted(directories, key=lambda x: len(x) if x != 'ROOT' else 0, reverse=True):

Refactoring the sorting of directories to a more concise and readable format improves code maintainability. This change also ensures that 'ROOT' is properly handled as a special case.

directories, key=lambda x: len(x) if x != "ROOT" else 0, reverse=True
):
children = sorted(node for node in graph.successors(dir))
document = f"{dir}\n" + "\n".join(children)
checksum = hash_str("".join(checksums[Path(child)] for child in children))
data = {
"id": dir_str,
"id": dir,
"type": "directory",
"ref": dir_str,
"ref": dir,
"document": document,
"checksum": checksum,
}
graph.add_node(dir_str, **data)
checksums[dir] = checksum

for source, target in edges:
for id in (source, target):
if id not in graph:
raise RagdaemonError(f"Node {id} not found in graph")
graph.add_edge(source, target, type="hierarchy")
checksums[Path(dir)] = checksum
graph.nodes[dir].update(data)

# Sync with remote DB
ids = list(set(checksums.values()))
Expand Down
Loading