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