Skip to content

Commit 3bf9e60

Browse files
authored
Merge pull request #739 from dorismaduegbunam/fix/pagination-magic-numbers
Fix/pagination magic numbers
2 parents 1c1b636 + b3a0f64 commit 3bf9e60

4 files changed

Lines changed: 17 additions & 10 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
_Programmable, real-time payment streams and recurring subscriptions._
88

9+
i just need to create a draft pr
10+
911
## Overview
1012

1113
FlowFi allows users to create continuous payment streams and recurring subscriptions using stablecoins on the Stellar network. By leveraging Soroban smart contracts, FlowFi enables autonomous accurate-to-the-second distribution of funds.

backend/src/controllers/stream.controller.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import {
1212
resumeStream as sorobanResumeStream,
1313
} from '../services/sorobanService.js';
1414
import type { AuthenticatedRequest } from '../types/auth.types.js';
15+
import { DEFAULT_EVENTS_PAGE_SIZE, MAX_EVENTS_PAGE_SIZE } from '../routes/v1/events.routes.js';
16+
17+
const DEFAULT_STREAM_PAGE_SIZE = 20;
18+
const MAX_STREAM_PAGE_SIZE = 100;
1519

1620
interface UserStreamSummary {
1721
address: string;
@@ -170,8 +174,8 @@ export const listStreams = async (req: Request, res: Response) => {
170174

171175
// Validate and parse pagination parameters
172176
const parsedLimit = Math.min(
173-
typeof limit === 'string' ? (Number.parseInt(limit, 10) || 20) : 20,
174-
100
177+
typeof limit === 'string' ? (Number.parseInt(limit, 10) || DEFAULT_STREAM_PAGE_SIZE) : DEFAULT_STREAM_PAGE_SIZE,
178+
MAX_STREAM_PAGE_SIZE
175179
);
176180
const parsedOffset = typeof offset === 'string' ? (Number.parseInt(offset, 10) || 0) : 0;
177181

@@ -285,8 +289,8 @@ export const getStreamEvents = async (req: Request, res: Response) => {
285289
const eventType = typeof req.query['eventType'] === 'string' ? req.query['eventType'] : undefined;
286290

287291
const limit = Math.min(
288-
rawLimit && typeof rawLimit === 'string' ? (Number.parseInt(rawLimit, 10) || 50) : 50,
289-
500,
292+
rawLimit && typeof rawLimit === 'string' ? (Number.parseInt(rawLimit, 10) || DEFAULT_EVENTS_PAGE_SIZE) : DEFAULT_EVENTS_PAGE_SIZE,
293+
MAX_EVENTS_PAGE_SIZE,
290294
);
291295

292296
let offset = 0;

backend/src/controllers/user.controller.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { prisma } from '../lib/prisma.js';
33
import logger from '../logger.js';
44
import { registerUserSchema } from '../validators/user.validator.js';
55
import type { AuthenticatedRequest } from '../types/auth.types.js';
6+
import { DEFAULT_EVENTS_PAGE_SIZE, MAX_EVENTS_PAGE_SIZE } from '../routes/v1/events.routes.js';
67

78
/**
89
* Register a new wallet public key
@@ -81,8 +82,8 @@ export const getUserEvents = async (req: Request, res: Response, next: NextFunct
8182
const rawOffset = req.query['offset'];
8283

8384
const limit = Math.min(
84-
rawLimit && typeof rawLimit === 'string' ? (Number.parseInt(rawLimit, 10) || 50) : 50,
85-
200
85+
rawLimit && typeof rawLimit === 'string' ? (Number.parseInt(rawLimit, 10) || DEFAULT_EVENTS_PAGE_SIZE) : DEFAULT_EVENTS_PAGE_SIZE,
86+
MAX_EVENTS_PAGE_SIZE
8687
);
8788
const offset = rawOffset && typeof rawOffset === 'string' ? (Number.parseInt(rawOffset, 10) || 0) : 0;
8889

backend/src/routes/v1/events.routes.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ const EVENT_TYPES = new Set([
2121
'ADMIN_TRANSFERRED',
2222
]);
2323

24-
const MAX_EVENT_LIMIT = 200;
25-
const DEFAULT_EVENT_LIMIT = 50;
24+
export const MAX_EVENTS_PAGE_SIZE = 200;
25+
export const DEFAULT_EVENTS_PAGE_SIZE = 50;
2626

2727
/**
2828
* @openapi
@@ -86,8 +86,8 @@ router.get('/', async (req: Request, res: Response, next: NextFunction) => {
8686

8787
const parsedLimit = Number.parseInt(String(req.query.limit ?? ''), 10);
8888
const limit = Number.isFinite(parsedLimit) && parsedLimit > 0
89-
? Math.min(parsedLimit, MAX_EVENT_LIMIT)
90-
: DEFAULT_EVENT_LIMIT;
89+
? Math.min(parsedLimit, MAX_EVENTS_PAGE_SIZE)
90+
: DEFAULT_EVENTS_PAGE_SIZE;
9191

9292
const hasOffset = req.query.offset !== undefined;
9393
const parsedOffset = Number.parseInt(String(req.query.offset ?? ''), 10);

0 commit comments

Comments
 (0)