From d99ff461b7443b34e06184ed81694c021071ca5c Mon Sep 17 00:00:00 2001 From: Namekuji Date: Sat, 5 Aug 2023 04:52:22 -0400 Subject: [PATCH] refactor: pass object param --- packages/backend/src/db/scylla.ts | 45 ++++++++++++++----------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/packages/backend/src/db/scylla.ts b/packages/backend/src/db/scylla.ts index 2dd4e5e54d..3ccfaa75e7 100644 --- a/packages/backend/src/db/scylla.ts +++ b/packages/backend/src/db/scylla.ts @@ -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 { 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[] = [];