scripts/apache-log-rate: Attempt to speed up with an array slice

This commit is contained in:
Athanasius 2022-02-10 16:17:49 +00:00
parent cb1991739e
commit 42129a50ce

View File

@ -45,9 +45,20 @@ def process_log_file(
# print(f'Timestamp: {this_dt}') # print(f'Timestamp: {this_dt}')
window_dts.append(this_dt) window_dts.append(this_dt)
# Find the oldest entry that is still within the window:
oldest_of_interest = this_dt - window_time_delta
dti = 0
for dt in window_dts:
if dt >= oldest_of_interest:
break
dti += 1
window_dts = window_dts[dti:]
# Now we need to expire any of the oldest stored timestamps that # Now we need to expire any of the oldest stored timestamps that
# are outside the window relative to this # are outside the window relative to this
window_dts = list(filter(lambda dt: dt >= this_dt - window_time_delta, window_dts)) # window_dts = list(filter(lambda dt: dt >= this_dt - window_time_delta, window_dts))
if len(window_dts) > window_count: if len(window_dts) > window_count:
window_count = len(window_dts) window_count = len(window_dts)