Skip to content

Commit

Permalink
Make function linear instead of quadratic
Browse files Browse the repository at this point in the history
  • Loading branch information
understreck committed Nov 29, 2023
1 parent 9b0ccd0 commit b8ecccc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 5 additions & 1 deletion koseki/plugins/metric/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,13 @@ def __calc_metric_payment(self) -> None:
payments[0].registered.date(), datetime.min.time())
else:
time = metrics[0].time

metrics_idx : int = 0
while time <= datetime.now():
# Only insert the metric row if it doesn't already exist.
if sum(1 for metric in metrics if metric.time == time) == 0:
while metrics_idx < (len(metrics) - 1) and metrics[metrics_idx].time < time:
metrics_idx += 1
if len(metrics) == 0 or metrics[metrics_idx].time != time:
total: float = 0.0
for payment in payments:
if payment.registered < time:
Expand Down
5 changes: 3 additions & 2 deletions requirements/common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ argon2-cffi>=20.1.0
email-validator>=1.1.2
flask-multistatic>=1.0
flask-wtf>=0.14.3
flask>=1.1.2
flask==1.1.2
libsass>=0.20.1
logging_prometheus>=0.1.0
lxml>=4.6.2
Expand All @@ -12,4 +12,5 @@ prometheus-flask-exporter>=0.18.1
pyop>=3.2.0
pyjwkest>=1.4.2
requests>=2.25.1
SQLAlchemy>=1.4.15
SQLAlchemy==1.4.15
markupsafe==2.0.1

0 comments on commit b8ecccc

Please sign in to comment.