From acd51a7058974d8dfb25c241b6810d27ac355850 Mon Sep 17 00:00:00 2001 From: link2xt Date: Mon, 19 Apr 2021 23:44:28 +0300 Subject: [PATCH] Sort global message search result only by ID It reduces the time by ~20% according to `search_msgs` benchmark. Sorting by IDs is sufficient for global search as IDs increase in the order of message reception. --- src/context.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/context.rs b/src/context.rs index 611c798e6..51f273bba 100644 --- a/src/context.rs +++ b/src/context.rs @@ -500,6 +500,11 @@ impl Context { .collect::>>() .await? } else { + // For performance reasons results are sorted only by `id`, that is in the order of + // message reception. + // + // Unlike chat view, sorting by `timestamp` is not necessary but slows down the query by + // ~25% according to benchmarks. self.sql .fetch( sqlx::query( @@ -514,7 +519,7 @@ impl Context { AND c.blocked=0 AND ct.blocked=0 AND (m.txt LIKE ? OR ct.name LIKE ?) - ORDER BY m.timestamp DESC,m.id DESC;", + ORDER BY m.id DESC", ) .bind(str_like_in_text) .bind(str_like_beg),