Optimize hot queries
`getLastConversationX()` is called from debounced function, but depending on how fast the fetch from the server is the actual invocations could happen for every other message. Prepare and optimize queries to save time.
This commit is contained in:
parent
f7cc23e034
commit
af9e038add
1 changed files with 16 additions and 18 deletions
|
@ -2966,10 +2966,10 @@ async function getLastConversationActivity({
|
||||||
ourConversationId: string;
|
ourConversationId: string;
|
||||||
}): Promise<MessageType | undefined> {
|
}): Promise<MessageType | undefined> {
|
||||||
const db = getInstance();
|
const db = getInstance();
|
||||||
const row = db
|
const row = prepare(
|
||||||
.prepare<Query>(
|
db,
|
||||||
`
|
`
|
||||||
SELECT * FROM messages
|
SELECT json FROM messages
|
||||||
WHERE
|
WHERE
|
||||||
conversationId = $conversationId AND
|
conversationId = $conversationId AND
|
||||||
(type IS NULL
|
(type IS NULL
|
||||||
|
@ -2997,11 +2997,10 @@ async function getLastConversationActivity({
|
||||||
ORDER BY received_at DESC, sent_at DESC
|
ORDER BY received_at DESC, sent_at DESC
|
||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
`
|
`
|
||||||
)
|
).get({
|
||||||
.get({
|
conversationId,
|
||||||
conversationId,
|
ourConversationId,
|
||||||
ourConversationId,
|
});
|
||||||
});
|
|
||||||
|
|
||||||
if (!row) {
|
if (!row) {
|
||||||
return undefined;
|
return undefined;
|
||||||
|
@ -3017,10 +3016,10 @@ async function getLastConversationPreview({
|
||||||
ourConversationId: string;
|
ourConversationId: string;
|
||||||
}): Promise<MessageType | undefined> {
|
}): Promise<MessageType | undefined> {
|
||||||
const db = getInstance();
|
const db = getInstance();
|
||||||
const row = db
|
const row = prepare(
|
||||||
.prepare<Query>(
|
db,
|
||||||
`
|
`
|
||||||
SELECT * FROM messages
|
SELECT json FROM messages
|
||||||
WHERE
|
WHERE
|
||||||
conversationId = $conversationId AND
|
conversationId = $conversationId AND
|
||||||
(
|
(
|
||||||
|
@ -3043,11 +3042,10 @@ async function getLastConversationPreview({
|
||||||
ORDER BY received_at DESC, sent_at DESC
|
ORDER BY received_at DESC, sent_at DESC
|
||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
`
|
`
|
||||||
)
|
).get({
|
||||||
.get({
|
conversationId,
|
||||||
conversationId,
|
ourConversationId,
|
||||||
ourConversationId,
|
});
|
||||||
});
|
|
||||||
|
|
||||||
if (!row) {
|
if (!row) {
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue