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
@@ -10,6 +10,8 @@ import {
OperationCategory,
} from '../presentation/brokerage-operation.dto';
const MISSING_TIMESTAMP_COMPONENT = 0;
const NANOSECONDS_PER_MILLISECOND = 1_000_000;
const types: Record<string, OperationCategory> = {
@@ -89,7 +91,7 @@ export function operationTimestamp(
value: undefined | { nanos?: number; seconds?: number | string },
) {
return new Date(
Number(value?.seconds ?? 0) * MILLISECONDS_PER_SECOND +
Math.floor((value?.nanos ?? 0) / NANOSECONDS_PER_MILLISECOND),
Number(value?.seconds ?? MISSING_TIMESTAMP_COMPONENT) * MILLISECONDS_PER_SECOND +
Math.floor((value?.nanos ?? MISSING_TIMESTAMP_COMPONENT) / NANOSECONDS_PER_MILLISECOND),
);
}
@@ -22,12 +22,21 @@ import {
type OperationInterval,
operationIntervals,
operationIntervalsOverlap,
operationsSyncPriority,
uncoveredOperationIntervals,
} from '../domain/operations-sync-plan';
import {
operationCategory,
operationTimestamp,
} from './brokerage-operation.mapper';
const CURSOR_LOOKAHEAD_ROWS = 1;
const EMPTY_INTERVAL_COUNT = 0;
const SINGLE_WORK_GROUP = 1;
const INITIAL_PAGE_COUNT = 0;
const PAGE_INCREMENT = 1;
const EXPECTED_UPDATED_WORK_ITEMS = 1;
export type { OperationInterval } from '../domain/operations-sync-plan';
export type OperationAttempt = {
@@ -202,7 +211,7 @@ export class BrokerageOperationsRepository {
{ accountId: 'asc' },
{ brokerOperationId: 'asc' },
],
...(input.limit === undefined ? {} : { take: input.limit + 1 }),
...(input.limit === undefined ? {} : { take: input.limit + CURSOR_LOOKAHEAD_ROWS }),
});
return {
connection,
@@ -280,7 +289,7 @@ export class BrokerageOperationsRepository {
) {
throw new NotFoundException();
}
if (priority > 1) {
if (priority > operationsSyncPriority.screen) {
for (const account of accounts.filter((account) =>
intervals.some(
(interval) => interval.accountId === account.accountId,
@@ -331,7 +340,7 @@ export class BrokerageOperationsRepository {
to: row.to,
instrumentUid: interval.instrumentUid,
})),
).length === 0,
).length === EMPTY_INTERVAL_COUNT,
);
const active = await tx.tbankSyncWork.findMany({
where: {
@@ -366,7 +375,7 @@ export class BrokerageOperationsRepository {
const upgradeGroup =
publicationAtomic && previousIntent && !previousIntent.atomic;
if (
touching.length <= 1 &&
touching.length <= SINGLE_WORK_GROUP &&
previous?.state === 'running' &&
previous.processRunId === processRunId &&
runningAttempts.has(previous.attemptId) &&
@@ -394,10 +403,10 @@ export class BrokerageOperationsRepository {
screenIntervals: [
...new Set([
...(previousIntent?.screenIntervals ??
(previous.priority === 1 ?
(previous.priority === operationsSyncPriority.screen ?
(previousIntent?.intervals ?? []) :
[])),
...(priority === 1 ?
...(priority === operationsSyncPriority.screen ?
[...pending, ...additions]
.filter((item) =>
intervals.some((target) =>
@@ -460,7 +469,7 @@ export class BrokerageOperationsRepository {
await tx.tbankSyncStage.deleteMany({ where: { workId: previous.id } });
}
const targets =
recovering && !upgradeGroup && touching.length <= 1 ?
recovering && !upgradeGroup && touching.length <= SINGLE_WORK_GROUP ?
previous?.scopeKey === scopeKey ?
retained :
[...retained, ...uncoveredOperationIntervals(intervals, retained)] :
@@ -491,13 +500,13 @@ export class BrokerageOperationsRepository {
screenIntervals: targets
.filter(
(target) =>
(priority === 1 &&
(priority === operationsSyncPriority.screen &&
intervals.some((incoming) =>
operationIntervalsOverlap(target, incoming),
)) ||
(
previousIntent?.screenIntervals ??
(previous?.priority === 1 ?
(previous?.priority === operationsSyncPriority.screen ?
(previousIntent?.intervals ?? []) :
[])
).some((key) =>
@@ -505,7 +514,7 @@ export class BrokerageOperationsRepository {
),
)
.map(intervalKey),
atomic: atomicTargets.length > 0,
atomic: atomicTargets.length > EMPTY_INTERVAL_COUNT,
};
const data = {
intent,
@@ -703,7 +712,7 @@ export class BrokerageOperationsRepository {
...(progress?.seen ?? []),
...(response.hasNext ? [nextCursor] : []),
],
pages: (progress?.pages ?? 0) + 1,
pages: (progress?.pages ?? INITIAL_PAGE_COUNT) + PAGE_INCREMENT,
};
await tx.tbankSyncStage.upsert({
where: {
@@ -891,11 +900,11 @@ export class BrokerageOperationsRepository {
priority: remaining.some((key) =>
(
intent.screenIntervals ??
(work.priority === 1 ? intent.intervals : [])
(work.priority === operationsSyncPriority.screen ? intent.intervals : [])
).includes(key),
) ?
1 :
2,
operationsSyncPriority.screen :
operationsSyncPriority.history,
progress: { remainingIntervals: remaining.length },
},
});
@@ -932,7 +941,7 @@ async function claim(
},
data: { updatedAt: new Date() },
});
return result.count === 1;
return result.count === EXPECTED_UPDATED_WORK_ITEMS;
}
function decodeInterval(key: string): OperationInterval {