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

RDISCROWD-5378: Task browse perf. format date utc -> est #762

Merged
merged 1 commit into from
Aug 17, 2022
Merged
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
19 changes: 15 additions & 4 deletions pybossa/cache/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,10 @@ def format_date(date):

def format_task(row, lock_users=[]):
"""convert database record to task dictionary and format data."""
finish_time = format_date(row.ft)
created = format_date(row.created)
user_pref = row.user_pref or {}
task = dict(id=row.id, n_task_runs=row.n_task_runs,
n_answers=row.n_answers, priority_0=row.priority_0,
finish_time=finish_time, created=created,
finish_time=row.ft, created=row.created,
calibration=row.calibration,
userPrefLang=", ".join(user_pref.get("languages", [])),
userPrefLoc=", ".join(user_pref.get("locations", [])),
Expand All @@ -89,6 +87,11 @@ def format_task(row, lock_users=[]):
task['pct_status'] = _pct_status(row.n_task_runs, row.n_answers)
return task

def format_task_dates(task):
"""convert created and finish date utc to est."""
task["created"] = format_date(task["created"])
task["finish_time"] = format_date(task["finish_time"])

def search_lock_status_sorting_result():
tasks = []
sql_order_by = sorting[order_by]
Expand Down Expand Up @@ -214,8 +217,11 @@ def search_lock_status_sorting_result():
tasks = select_available_tasks(task_rank_info, locked_tasks_in_project,
user_id, offset+limit, args.get("order_by"),
eligible_tasks=unreserved_task_ids)

tasks = tasks[offset: offset+limit]
# format current page task dates utc to est
# this is to obtain 10x better response time
for task in tasks:
format_task_dates(task)

else:
# construct task browse page for owners/admins
Expand Down Expand Up @@ -252,6 +258,11 @@ def search_lock_status_sorting_result():
results = session.execute(text(sql_query), params)
tasks = [format_task(row, locked_tasks_in_project.get(row.id, [])) for row in results]

# format first 100 task dates utc to est
# this is to obtain 10x better response time
num_tasks = min(len(tasks), 100)
for i in range(num_tasks):
XiChenn marked this conversation as resolved.
Show resolved Hide resolved
format_task_dates(tasks[i])
session.execute("RESET enable_indexscan;")

return total_count, tasks
Expand Down