Spaces:
Build error
Build error
Limit number of fetched conversations in the API (#954)
Browse files* Limit number of fetched conversations in the API
* Add pagination
* use var
src/routes/api/conversations/+server.ts
CHANGED
@@ -2,7 +2,11 @@ import { collections } from "$lib/server/database";
|
|
2 |
import { authCondition } from "$lib/server/auth";
|
3 |
import type { Conversation } from "$lib/types/Conversation";
|
4 |
|
5 |
-
|
|
|
|
|
|
|
|
|
6 |
if (locals.user?._id || locals.sessionId) {
|
7 |
const convs = await collections.conversations
|
8 |
.find({
|
@@ -14,6 +18,8 @@ export async function GET({ locals }) {
|
|
14 |
model: 1,
|
15 |
})
|
16 |
.sort({ updatedAt: -1 })
|
|
|
|
|
17 |
.toArray();
|
18 |
|
19 |
const res = convs.map((conv) => ({
|
|
|
2 |
import { authCondition } from "$lib/server/auth";
|
3 |
import type { Conversation } from "$lib/types/Conversation";
|
4 |
|
5 |
+
const NUM_PER_PAGE = 300;
|
6 |
+
|
7 |
+
export async function GET({ locals, url }) {
|
8 |
+
const p = parseInt(url.searchParams.get("p") ?? "0");
|
9 |
+
|
10 |
if (locals.user?._id || locals.sessionId) {
|
11 |
const convs = await collections.conversations
|
12 |
.find({
|
|
|
18 |
model: 1,
|
19 |
})
|
20 |
.sort({ updatedAt: -1 })
|
21 |
+
.skip(p * NUM_PER_PAGE)
|
22 |
+
.limit(NUM_PER_PAGE)
|
23 |
.toArray();
|
24 |
|
25 |
const res = convs.map((conv) => ({
|