Skip to content

Commit 050a405

Browse files
authored
perf: avoid urljoin for absolute urls (#10896)
This makes locking 15 % faster in some cases.
1 parent c04069d commit 050a405

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/poetry/repositories/link_sources/json.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,14 @@ def __init__(self, url: str, content: dict[str, Any]) -> None:
2828
def _link_cache(self) -> LinkCache:
2929
links: LinkCache = defaultdict(lambda: defaultdict(list))
3030
for file in self.content["files"]:
31-
url = self.clean_link(urllib.parse.urljoin(self._url, file["url"]))
31+
file_url = file["url"]
32+
# This is just a performance shortcut.
33+
# urljoin would work just fine for absolute URLs as well,
34+
# but it is much faster to skip urljoin in that case.
35+
# (Links on pypi.org are absolute.)
36+
if not file_url.startswith(("http://", "https://", "file://")):
37+
file_url = urllib.parse.urljoin(self._url, file_url)
38+
url = self.clean_link(file_url)
3239
requires_python = file.get("requires-python")
3340
hashes = file.get("hashes", {})
3441
yanked = file.get("yanked", False)

0 commit comments

Comments
 (0)