refactor: pass object param
This commit is contained in:
parent
a26553dc18
commit
d99ff461b7
1 changed files with 20 additions and 25 deletions
|
@ -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[] = [];
|
||||||
|
|
Loading…
Reference in a new issue