Skip to content

Commit

Permalink
Speedups (#54)
Browse files Browse the repository at this point in the history
* build directory nodes from graph instead of filesys

* version bump
  • Loading branch information
granawkins authored Jun 21, 2024
1 parent adb334f commit 5bc1bbc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 26 deletions.
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"
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())
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:
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(
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

0 comments on commit 5bc1bbc

Please sign in to comment.