Skip to content

Commit

Permalink
Fix: All node metrics were returned by default
Browse files Browse the repository at this point in the history
This causes a lot of data to be returned in the case of old nodes and is usually unnecessary.

Solution: Default to limiting the query to the last 2 weeks of data, or to 2 weeks before the specified date of last data.
  • Loading branch information
hoh committed Jan 24, 2024
1 parent 858964d commit 963850f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/aleph/db/accessors/metrics.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import time
from typing import Optional

from sqlalchemy import select, text
Expand Down Expand Up @@ -66,6 +67,12 @@ def query_metric_ccn(
end_date: Optional[float] = None,
sort_order: Optional[str] = None,
):
# Default to the last 2 weeks from now, or 2 weeks before the `end_date`.
if not start_date and not end_date:
start_date = time.time() - 60 * 60 * 24 * 14
elif end_date and not start_date:
start_date = end_date - 60 * 60 * 24 * 14

select_stmt = select(
[
text("item_hash"),
Expand Down Expand Up @@ -100,6 +107,12 @@ def query_metric_crn(
end_date: Optional[float] = None,
sort_order: Optional[str] = None,
):
# Default to the last 2 weeks from now, or 2 weeks before the `end_date`.
if not start_date and not end_date:
start_date = time.time() - 60 * 60 * 24 * 14
elif end_date and not start_date:
start_date = end_date - 60 * 60 * 24 * 14

select_stmt = select(
[
text("item_hash"),
Expand Down

0 comments on commit 963850f

Please sign in to comment.