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.
This commit is contained in:
link2xt
2021-04-19 23:44:28 +03:00
parent 61bf0b208c
commit acd51a7058

View File

@@ -500,6 +500,11 @@ impl Context {
.collect::<sqlx::Result<Vec<MsgId>>>()
.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),