fix: param building
This commit is contained in:
parent
2be2ab9153
commit
bfc96e3c8a
2 changed files with 6 additions and 7 deletions
|
@ -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,
|
||||||
|
|
|
@ -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,
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue