Skip to content

Commit

Permalink
Re-order query for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
markwaddle committed Oct 29, 2024
1 parent 32c362c commit 6d4f3ae
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions workbench-service/semantic_workbench_service/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,6 @@ def select_conversation_projections_for(
include_all_owned: bool = False,
include_observer: bool = False,
) -> Select[tuple[db.Conversation, db.ConversationMessage | None, str]]:
latest_message_subquery = (
select(
db.ConversationMessage.conversation_id,
func.max(db.ConversationMessage.sequence).label("latest_message_sequence"),
)
.group_by(col(db.ConversationMessage.conversation_id))
.subquery()
)

match principal:
case auth.UserPrincipal():
select_query = select(
Expand All @@ -152,6 +143,15 @@ def select_conversation_projections_for(
select_query=select_query,
)

latest_message_subquery = (
select(
db.ConversationMessage.conversation_id,
func.max(db.ConversationMessage.sequence).label("latest_message_sequence"),
)
.group_by(col(db.ConversationMessage.conversation_id))
.subquery()
)

return query.join_from(
db.Conversation,
latest_message_subquery,
Expand Down

0 comments on commit 6d4f3ae

Please sign in to comment.