Skip to content

Commit

Permalink
switches order of version checking conditions for better performance
Browse files Browse the repository at this point in the history
  • Loading branch information
edublancas committed Feb 21, 2022
1 parent a85a156 commit 976012e
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/ploomber/telemetry/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,18 +362,20 @@ def check_version():
and not conf['version_check_enabled']:
return

# If latest version, do nothing
latest = get_latest_version()

if __version__ == latest:
return

# Check if we already notified in the last 2 days
last_message = version['last_version_check']
diff = (today - last_message).days
if diff < 2:
return

# check latest version (this is an expensive call since it hits pypi.org)
# so we only ping the server when it's been 2 days
latest = get_latest_version()

# If latest version, do nothing
if __version__ == latest:
return

click.secho(
f"There's a new Ploomber version available ({latest}), "
f"you're running {__version__}. To upgrade: "
Expand Down Expand Up @@ -498,7 +500,6 @@ def log_api(action, client_time=None, total_runtime=None, metadata=None):
def log_call(action, payload=False):
"""Runs a function and logs it
"""

def _log_call(func):
@wraps(func)
def wrapper(*args, **kwargs):
Expand Down

0 comments on commit 976012e

Please sign in to comment.