MCPcopy Index your code
hub / github.com/ChatLab/ChatLab / fetchMessagesBefore

Function fetchMessagesBefore

packages/core/src/query/message-query-functions.ts:68–82  ·  view source on GitHub ↗
(
  executor: AsyncSqlExecutor,
  beforeId: number,
  limit: number = 50,
  filter?: TimeFilter,
  senderId?: number,
  keywords?: string[]
)

Source from the content-addressed store, hash-verified

66 * Results are returned in ascending order (oldest → newest).
67 */
68export async function fetchMessagesBefore(
69 executor: AsyncSqlExecutor,
70 beforeId: number,
71 limit: number = 50,
72 filter?: TimeFilter,
73 senderId?: number,
74 keywords?: string[]
75): Promise<AsyncPaginatedMessages> {
76 const { clause, params } = filterConditions(filter, senderId, keywords)
77 const sql = `${FULL_MSG_SELECT} WHERE msg.id < ? ${clause} ORDER BY msg.id DESC LIMIT ?`
78 const rows = await executor.all<FullMessageRow>(sql, [beforeId, ...params, limit + 1])
79 const hasMore = rows.length > limit
80 const sliced = hasMore ? rows.slice(0, limit) : rows
81 return { messages: sliced.map(mapMessageRow).reverse(), hasMore }
82}
83
84/**
85 * Fetch N messages after a given id (infinite scroll downward).

Callers 3

getMessagesBeforeFunction · 0.90
getMessagesBeforeMethod · 0.90

Calls 1

filterConditionsFunction · 0.85

Tested by

no test coverage detected