Skip to content

Commit

Permalink
subquery
Browse files Browse the repository at this point in the history
  • Loading branch information
codabrink committed Dec 19, 2024
1 parent d155744 commit 3395aa8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 3 additions & 3 deletions bindings_ffi/src/mls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1326,10 +1326,10 @@ impl FfiConversation {
.find_messages(&MsgQueryArgs {
sent_before_ns: opts.sent_before_ns,
sent_after_ns: opts.sent_after_ns,
kind: kind,
delivery_status: delivery_status,
limit: opts.limit,
direction: direction,
kind,
delivery_status,
direction,
})?
.into_iter()
.map(|msg| msg.into())
Expand Down
10 changes: 9 additions & 1 deletion xmtp_mls/src/storage/encrypted_store/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,16 @@ impl DbConnection {
} = args.as_ref();

let mut query = groups_dsl::groups
// Filter out sync groups from the main query
.filter(groups_dsl::conversation_type.ne(ConversationType::Sync))
// Group by dm_id and grab the latest group (conversation stitching)
.filter(sql::<diesel::sql_types::Bool>(
"id IN (
SELECT id
FROM groups
GROUP BY dm_id, CASE WHEN dm_id IS NULL THEN id ELSE dm_id END
ORDER BY last_message_ns DESC
)",
))
.order(groups_dsl::created_at_ns.asc())
.into_boxed();

Expand Down

0 comments on commit 3395aa8

Please sign in to comment.