Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Improve performance of result list API #155

Merged
merged 3 commits into from
Sep 14, 2018
Merged
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions chainerui/tasks/crawl_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _check_log_updated(result):
return False


def crawl_result(result, force=False):
def crawl_result(result, force=False, commit=True):
"""crawl_results."""
now = datetime.datetime.now()

Expand Down Expand Up @@ -102,6 +102,7 @@ def crawl_result(result, force=False):
)

result.updated_at = datetime.datetime.now()
db.session.commit()
if commit:
db.session.commit()

return result
14 changes: 8 additions & 6 deletions chainerui/views/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ def get(self, id=None, project_id=None):
filter_by(is_unregistered=False).\
all()

# NOTE: To improve performance, aggregate commit phase. By set
# `commit=False`, implicit transaction is not closed, UPDATE query
# is not committed. Consequently a process of serializing does not
# have to call SELECT query again.
for result in results:
result = crawl_result(result)
crawl_result(result, commit=False)
rs = [r.serialize_with_sampled_logs(logs_limit) for r in results]
db.session.commit()

return jsonify({
'results': [
r.serialize_with_sampled_logs(logs_limit) for r in results
]
})
return jsonify({'results': rs})

else:

Expand Down