Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates email report to query one day at a time. #94

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions utils/email_db_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,16 @@ def str_to_date(date_str, by_day=True):
return datetime.datetime.strptime(date_str, date_format)

def run_query_for_days(query_str, today, days=7):
today_str = date_to_str(today, by_day=False)
last_week = today - datetime.timedelta(days=days)
last_week_str = date_to_str(last_week, by_day=False)

result = db_session.execute(query_str, {"from_date": last_week_str, "to_date": today_str}).fetchall()
result = []
# Some queries (mod_actions) can cause mysql to run out of memory
# Querying a day at a time reduces the memory usage
for day in range(days):
days_ago = days - day
from_dt = today - datetime.timedelta(days=days_ago)
from_str = date_to_str(from_dt, by_day=False)
to_dt = from_dt + datetime.timedelta(days=1)
to_str = date_to_str(to_dt, by_day=False)
result += list(db_session.execute(query_str, {"from_date": from_str, "to_date": to_str}).fetchall())
return result

def transform_result_to_dict(result):
Expand Down