refactor: pass object param

This commit is contained in:
Namekuji 2023-08-05 04:52:22 -04:00
parent a26553dc18
commit d99ff461b7
No known key found for this signature in database
GPG key ID: 1D62332C07FBA532

View file

@ -187,29 +187,29 @@ export function parseScyllaReaction(row: types.Row): ScyllaNoteReaction {
}; };
} }
export function prepareTimelineQuery( export function prepareTimelineQuery(ps: {
untilId?: string, untilId?: string;
untilDate?: number, untilDate?: number;
sinceId?: string, sinceId?: string;
sinceDate?: number, sinceDate?: number;
): { query: string; untilDate: Date; sinceDate: Date | null } { }): { query: string; untilDate: Date; sinceDate: Date | null } {
const queryParts = [`${prepared.note.select.byDate} AND "createdAt" < ?`]; const queryParts = [`${prepared.note.select.byDate} AND "createdAt" < ?`];
let _untilDate = new Date(); let until = new Date();
if (untilId) { if (ps.untilId) {
_untilDate = new Date(getTimestamp(untilId)); until = new Date(getTimestamp(ps.untilId));
} }
if (untilDate && untilDate < _untilDate.getTime()) { if (ps.untilDate && ps.untilDate < until.getTime()) {
_untilDate = new Date(untilDate); until = new Date(ps.untilDate);
} }
let _sinceDate: Date | null = null; let since: Date | null = null;
if (sinceId) { if (ps.sinceId) {
_sinceDate = new Date(getTimestamp(sinceId)); since = new Date(getTimestamp(ps.sinceId));
} }
if (sinceDate && (!_sinceDate || sinceDate > _sinceDate.getTime())) { if (ps.sinceDate && (!since || ps.sinceDate > since.getTime())) {
_sinceDate = new Date(sinceDate); since = new Date(ps.sinceDate);
} }
if (_sinceDate !== null) { if (since !== null) {
queryParts.push(`AND "createdAt" > ?`); queryParts.push(`AND "createdAt" > ?`);
} }
@ -218,8 +218,8 @@ export function prepareTimelineQuery(
return { return {
query, query,
untilDate: _untilDate, untilDate: until,
sinceDate: _sinceDate, sinceDate: since,
}; };
} }
@ -236,12 +236,7 @@ export async function execTimelineQuery(
): Promise<ScyllaNote[]> { ): Promise<ScyllaNote[]> {
if (!scyllaClient) return []; if (!scyllaClient) return [];
let { query, untilDate, sinceDate } = prepareTimelineQuery( let { query, untilDate, sinceDate } = prepareTimelineQuery(ps);
ps.untilId,
ps.untilDate,
ps.sinceId,
ps.sinceDate,
);
let scannedPartitions = 0; let scannedPartitions = 0;
const foundNotes: ScyllaNote[] = []; const foundNotes: ScyllaNote[] = [];