perf(api,frontend): index hot queries, paginate chats, fix realtime
This commit is contained in:
1 parent
9d767d2531
commit
525ce024bc
27 files changed
+831
-268
No files matched your search
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { untrack } from "svelte";
|
||||
import { getPeers, getStories } from "$lib/api/endpoints";
|
||||
import { getChat, getPeers, getStories } from "$lib/api/endpoints";
|
||||
import { loadStoryMedia } from "$lib/api/stories";
|
||||
import type { StoryView } from "$lib/api/types";
|
||||
import StoryViewer from "$lib/components/stories/StoryViewer.svelte";
|
||||
@@ -10,7 +10,6 @@
|
||||
import Spinner from "$lib/components/ui/Spinner.svelte";
|
||||
import { peerName } from "$lib/format/peer";
|
||||
import { accounts } from "$lib/stores/accounts.svelte";
|
||||
import { chats } from "$lib/stores/chats.svelte";
|
||||
|
||||
interface Group {
|
||||
hasAvatar: boolean;
|
||||
@@ -50,11 +49,20 @@
|
||||
}
|
||||
}
|
||||
const peerIds = [...byPeer.keys()].filter((id) => id > 0);
|
||||
const peers = await getPeers(peerIds);
|
||||
const chatIds = [...byPeer.keys()].filter((id) => id < 0);
|
||||
const [peers, fetched] = await Promise.all([
|
||||
getPeers(peerIds),
|
||||
Promise.all(chatIds.map((id) => getChat(id))),
|
||||
]);
|
||||
if (current !== token) {
|
||||
return;
|
||||
}
|
||||
const peerById = new Map(peers.map((peer) => [peer.peer_id, peer]));
|
||||
const chatById = new Map(
|
||||
fetched
|
||||
.filter((item) => item !== null)
|
||||
.map((item) => [item.chat_id, item])
|
||||
);
|
||||
groups = [...byPeer.entries()].map(([peerId, stories]) => {
|
||||
if (peerId > 0) {
|
||||
const peer = peerById.get(peerId) ?? null;
|
||||
@@ -66,7 +74,7 @@
|
||||
stories,
|
||||
};
|
||||
}
|
||||
const chat = chats.byId(peerId);
|
||||
const chat = chatById.get(peerId);
|
||||
return {
|
||||
peerId,
|
||||
kind: "chat" as const,
|
||||
|
||||
Reference in new issue
Block a user