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

chore: use the most recent comment on observer exports #1024

Open
wants to merge 4 commits into
base: develop
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
20 changes: 16 additions & 4 deletions apollo/submissions/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,21 @@ def export_list(self, query, include_qa=False, include_group_timestamps=False):
yield output.getvalue()
output.close()

for item in query:
latest_comments_subquery = sa.select(
SubmissionComment,
sa.func.row_number()
.over(partition_by=SubmissionComment.submission_id, order_by=SubmissionComment.submit_date.desc())
.label("row_number"),
).subquery()

query2 = query.outerjoin(
latest_comments_subquery,
sa.and_(
Submission.id == latest_comments_subquery.c.submission_id, latest_comments_subquery.c.row_number == 1
),
).with_entities(Submission, latest_comments_subquery.c.comment)

for item, most_recent_comment in query2:
if export_qa:
row_dict = item._asdict()
submission = row_dict["Submission"]
Expand Down Expand Up @@ -169,9 +183,7 @@ def export_list(self, query, include_qa=False, include_group_timestamps=False):
[submission.updated.strftime("%Y-%m-%d %H:%M:%S") if submission.updated else ""]
+ [1 if sample in submission.participant.samples else 0 for sample in samples]
+ [
submission.comments[0].comment.replace("\n", "") # noqa
if submission.comments
else "",
(most_recent_comment or "").replace("\n", " ").strip(),
submission.quarantine_status.value if submission.quarantine_status else "",
]
)
Expand Down