fix: param building

This commit is contained in:
Namekuji 2023-08-09 22:24:54 -04:00
parent 2be2ab9153
commit bfc96e3c8a
No known key found for this signature in database
GPG key ID: 1D62332C07FBA532
2 changed files with 6 additions and 7 deletions

View file

@ -249,7 +249,7 @@ export function parseScyllaReaction(row: types.Row): ScyllaNoteReaction {
}; };
} }
export function prepareTimelineQuery(ps: { export function prepareNoteQuery(ps: {
untilId?: string; untilId?: string;
untilDate?: number; untilDate?: number;
sinceId?: string; sinceId?: string;
@ -280,7 +280,6 @@ export function prepareTimelineQuery(ps: {
queryParts.push(`AND "createdAt" > ?`); queryParts.push(`AND "createdAt" > ?`);
} }
queryParts.push("LIMIT ?");
const query = queryParts.join(" "); const query = queryParts.join(" ");
return { return {
@ -304,7 +303,7 @@ export async function execNotePaginationQuery(
): Promise<ScyllaNote[]> { ): Promise<ScyllaNote[]> {
if (!scyllaClient) return []; if (!scyllaClient) return [];
let { query, untilDate, sinceDate } = prepareTimelineQuery(ps); let { query, untilDate, sinceDate } = prepareNoteQuery(ps);
let scannedEmptyPartitions = 0; let scannedEmptyPartitions = 0;
const foundNotes: ScyllaNote[] = []; const foundNotes: ScyllaNote[] = [];
@ -313,13 +312,13 @@ export async function execNotePaginationQuery(
while (foundNotes.length < ps.limit && scannedEmptyPartitions < maxDays) { while (foundNotes.length < ps.limit && scannedEmptyPartitions < maxDays) {
const params: (Date | string | string[] | number)[] = []; const params: (Date | string | string[] | number)[] = [];
if (ps.noteId) { if (ps.noteId) {
params.push(ps.noteId); params.push(ps.noteId, untilDate);
} else {
params.push(untilDate, untilDate);
} }
params.push(untilDate, untilDate);
if (sinceDate) { if (sinceDate) {
params.push(sinceDate); params.push(sinceDate);
} }
params.push(ps.limit);
const result = await scyllaClient.execute(query, params, { const result = await scyllaClient.execute(query, params, {
prepare: true, prepare: true,

View file

@ -102,7 +102,7 @@ export default define(meta, paramDef, async (ps, user) => {
return filtered; return filtered;
}; };
const foundNotes = await execNotePaginationQuery(ps, filter); const foundNotes = await execNotePaginationQuery(ps, filter, 1);
return await Notes.packMany(foundNotes.slice(0, ps.limit), user, { return await Notes.packMany(foundNotes.slice(0, ps.limit), user, {
scyllaNote: true, scyllaNote: true,
}); });