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 2dfcf5b
Show file tree
Hide file tree
Showing 2 changed files with 8 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
6 changes: 5 additions & 1 deletion xmtp_mls/src/storage/encrypted_store/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use diesel::{
dsl::sql,
expression::AsExpression,
prelude::*,
query_builder::AsQuery,
query_dsl::methods::DistinctDsl,
serialize::{self, IsNull, Output, ToSql},
sql_types::Integer,
};
Expand Down Expand Up @@ -223,8 +225,10 @@ 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))
.filter(sql::<diesel::sql_types::Bool>(
"id IN (SELECT id FROM groups GROUP BY dm_id HAVING latest_message_ns = MAX(latest_message_ns))"
))
.order(groups_dsl::created_at_ns.asc())
.into_boxed();

Expand Down

0 comments on commit 2dfcf5b

Please sign in to comment.