Skip to content

[Low] GET /chat returns all chats without pagination #105

@bmersereau

Description

@bmersereau

Problem

backend/src/routes/chat.ts:141–166 — the GET /chat endpoint fetches every chat the user owns plus every chat in every project they own, with no limit:

const { data, error } = await db
  .from("chats")
  .select("*")
  .or(filter)
  .order("created_at", { ascending: false });
// no .limit()

For an active user with hundreds of chats (or an owner of a busy shared project), this is a large unbounded response on every page load, blocking the sidebar render.

Fix

Add limit / cursor-based pagination. A default of 50 chats per page is reasonable. The sidebar already renders a list — it can lazy-load older chats on scroll.

const limit = Math.min(Number(req.query.limit) || 50, 200);
const before = req.query.before as string | undefined;  // ISO timestamp cursor

// ...
let q = db.from("chats").select("*").or(filter).order("created_at", { ascending: false }).limit(limit);
if (before) q = q.lt("created_at", before);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions