-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Speed up get_num_partitions for common cases
Summary: Test Plan: A representative large asset graph with many partition sets goes from taking 65 second to computing counts on all assets to taking 0.4 seconds to compute counts on all assets
- Loading branch information
Showing
3 changed files
with
85 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
def is_basic_daily(cron_schedule: str) -> bool: | ||
return cron_schedule == "0 0 * * *" | ||
|
||
|
||
def is_basic_hourly(cron_schedule: str) -> bool: | ||
return cron_schedule == "0 * * * *" | ||
|
||
|
||
def get_fixed_minute_interval(cron_schedule: str): | ||
"""Given a cronstring, returns whether or not it is safe to | ||
assume there is a fixed number of minutes between every tick. For | ||
many cronstrings this is not the case due to Daylight Savings Time, | ||
but for basic hourly cron schedules and cron schedules like */15 it | ||
is safe to assume that there are a fixed number of minutes between each | ||
tick. | ||
""" | ||
if is_basic_hourly(cron_schedule): | ||
return 60 | ||
|
||
cron_parts = cron_schedule.split() | ||
is_wildcard = [part == "*" for part in cron_parts] | ||
|
||
# To match this criteria, every other field besides the first must end in * | ||
# since it must be an every-n-minutes cronstring like */15 | ||
if not is_wildcard[1:]: | ||
return None | ||
|
||
if not cron_parts[0].startswith("*/"): | ||
return None | ||
|
||
try: | ||
# interval makes up the characters after the "*/" | ||
interval = int(cron_parts[0][2:]) | ||
except ValueError: | ||
return None | ||
|
||
# cronstrings like */7 do not have a fixed interval because they jump | ||
# from :54 to :07, but divisors of 60 do | ||
if interval > 0 and interval < 60 and 60 % interval == 0: | ||
return interval | ||
|
||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters