From bd105a66095456add51e3e04e0840af93dacdb6d Mon Sep 17 00:00:00 2001 From: Aradhya Date: Mon, 28 Mar 2022 21:02:38 +0530 Subject: [PATCH] perf: caching deps and orgs, repos to avoid time taking checks & added slower version to check org and repo --- bench/utils/__init__.py | 4 ++++ bench/utils/app.py | 2 ++ 2 files changed, 6 insertions(+) diff --git a/bench/utils/__init__.py b/bench/utils/__init__.py index b815fb3a6..450d94929 100644 --- a/bench/utils/__init__.py +++ b/bench/utils/__init__.py @@ -8,6 +8,7 @@ from glob import glob from shlex import split from typing import List, Tuple +from functools import lru_cache # imports - third party imports import click @@ -421,6 +422,7 @@ def clear_command_cache(bench_path="."): print("Bench command cache doesn't exist in this folder!") +@lru_cache(maxsize=5) def find_org(org_repo): import requests @@ -428,6 +430,8 @@ def find_org(org_repo): for org in ["frappe", "erpnext"]: res = requests.head(f"https://api.github.com/repos/{org}/{org_repo}") + if "message" in res.json(): + res = requests.head(f"https://github.com/{org}/{org_repo}") if res.ok: return org, org_repo diff --git a/bench/utils/app.py b/bench/utils/app.py index 32e958f37..d07422e1b 100644 --- a/bench/utils/app.py +++ b/bench/utils/app.py @@ -10,6 +10,7 @@ VersionNotFound, ) from bench.app import get_repo_dir +from functools import lru_cache def is_version_upgrade(app="frappe", bench_path=".", branch=None): @@ -168,6 +169,7 @@ def get_current_branch(app, bench_path="."): return get_cmd_output("basename $(git symbolic-ref -q HEAD)", cwd=repo_dir) +@lru_cache(maxsize=5) def get_required_deps(org, name, branch, deps="hooks.py"): import requests import base64