refactor: replace ignored numeric literals with constants
Backend security / security (push) Successful in 8s
Backend verify / verify (push) Failing after 2m17s
Conventional commits / commits (pull_request) Successful in 31s
Backend security / security (pull_request) Successful in 8s
Backend verify / verify (pull_request) Failing after 1m56s

This commit is contained in:
2026-09-28 11:24:59 +03:00
parent 9b3558f96c
commit 9cc9fbdcff
60 changed files with 510 additions and 283 deletions
@@ -1,3 +1,11 @@
export const operationsSyncPriority = { screen: 1, history: 2 } as const;
const LAST_INTERVAL_INDEX = -1;
const NEXT_MONTH_OFFSET = 1;
const FIRST_DAY_OF_MONTH = 1;
const EMPTY_INTERVAL_COUNT = 0;
const EMPTY_SOURCE_COUNT = 0;
export type OperationInterval = {
accountId: string;
from: Date;
@@ -31,7 +39,7 @@ export function operationIntervals(
for (const interval of (groups.get(key) ?? []).sort(
(left, right) => left.from.valueOf() - right.from.valueOf(),
)) {
const previous = merged.at(-1);
const previous = merged.at(LAST_INTERVAL_INDEX);
if (previous && interval.from <= previous.to) {
previous.to = new Date(
Math.max(previous.to.valueOf(), interval.to.valueOf()),
@@ -42,7 +50,7 @@ export function operationIntervals(
let from = interval.from;
while (from < interval.to) {
const nextMonth = new Date(
Date.UTC(from.getUTCFullYear(), from.getUTCMonth() + 1, 1),
Date.UTC(from.getUTCFullYear(), from.getUTCMonth() + NEXT_MONTH_OFFSET, FIRST_DAY_OF_MONTH),
);
const to = new Date(
Math.min(nextMonth.valueOf(), interval.to.valueOf()),
@@ -111,7 +119,7 @@ export function planOperationRead(
options: { force?: boolean; movingEnd?: boolean } = {},
) {
const monthStart = new Date(
Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), 1),
Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), FIRST_DAY_OF_MONTH),
);
const observedEnd = Math.max(
...requested.map((interval) => interval.to.valueOf()),
@@ -146,10 +154,10 @@ export function planOperationRead(
}
}
const missing = uncoveredOperationIntervals([effective], ranges);
const complete = missing.length === 0;
const complete = missing.length === EMPTY_INTERVAL_COUNT;
const stale =
current &&
sources.length > 0 &&
sources.length > EMPTY_SOURCE_COUNT &&
uncoveredOperationIntervals(
ranges
.map((row) => ({
@@ -161,7 +169,7 @@ export function planOperationRead(
}))
.filter((row) => row.from < row.to),
fresh.map((row) => ({ ...row, instrumentUid: target.instrumentUid })),
).length > 0;
).length > EMPTY_INTERVAL_COUNT;
if (options.force) load.push(target);
else if (stale) load.push({ ...target, from: monthStart, to: now });
else load.push(...missing);