From fcc925a707235bce4d01626bcd6e3e732da0d835 Mon Sep 17 00:00:00 2001 From: Etienne Donneger Date: Mon, 29 Apr 2024 15:39:28 -0400 Subject: [PATCH] Change default limit to 1 --- src/fetch/openapi.ts | 2 +- src/queries.ts | 13 ++++++------- src/utils.ts | 6 +++--- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/fetch/openapi.ts b/src/fetch/openapi.ts index b24b9ef..a3623d6 100644 --- a/src/fetch/openapi.ts +++ b/src/fetch/openapi.ts @@ -17,7 +17,7 @@ const timestampExamplesArrayFilter = ["greater_or_equals_by_timestamp", "greater const blockExamplesArrayFilter = ["greater_or_equals_by_block", "greater_by_block", "less_or_equals_by_block", "less_by_block"]; const amountExamplesArrayFilter = ["amount_greater_or_equals", "amount_greater", "amount_less_or_equals", "amount_less"]; -const supply_example = await makeQuery(getTotalSupply(new URLSearchParams({ limit: "2" }), true)).then(res => addMetadata(res, 2, 1)); +const supply_example = await makeQuery(getTotalSupply(new URLSearchParams({ limit: "1" }), true)).then(res => addMetadata(res, 1, 1)); const balance_example = await makeQuery(getBalanceChanges(new URLSearchParams({ limit: "2" }), true)).then(res => addMetadata(res, 2, 1)); const transfers_example = await makeQuery(getTransfers(new URLSearchParams({ limit: "5" }), true)).then(res => addMetadata(res, 5, 1)); diff --git a/src/queries.ts b/src/queries.ts index 5ff3b65..236001d 100644 --- a/src/queries.ts +++ b/src/queries.ts @@ -82,7 +82,7 @@ export function getTotalSupply(searchParams: URLSearchParams, example?: boolean) query += ` ORDER BY block_number ${sort_by ?? DEFAULT_SORT_BY} `; } - const limit = parseLimit(searchParams.get("limit"), config.maxLimit); + const limit = parseLimit(searchParams.get("limit")); if (limit) query += ` LIMIT ${limit}`; const page = parsePage(searchParams.get("page")); @@ -115,7 +115,7 @@ export function getBalanceChanges(searchParams: URLSearchParams, example?: boole //if (contract && !account) query += `GROUP BY (contract, account) ORDER BY timestamp DESC`; } - const limit = parseLimit(searchParams.get("limit"), config.maxLimit); + const limit = parseLimit(searchParams.get("limit")); if (limit) query += ` LIMIT ${limit}`; const page = parsePage(searchParams.get("page")); @@ -132,10 +132,9 @@ export function getTransfers(searchParams: URLSearchParams, example?: boolean) { let query = "SELECT * FROM "; - if (searchParams.get("greater_or_equals_by_block") && searchParams.get("less_or_equals_by_block")) query += "transfers_block_num" - else if (from && !to) query += "transfers_from" + if (from && !to) query += "transfers_from" else if (!from && to) query += "transfers_to" - else query += "transfer_events" + else query += "transfers_block_num" if (!example) { // WHERE statements @@ -151,10 +150,10 @@ export function getTransfers(searchParams: URLSearchParams, example?: boolean) { if (where.length) query += ` WHERE(${where.join(' AND ')})`; - query += ` ORDER BY timestamp DESC`; + query += ` ORDER BY block_num DESC`; } - const limit = parseLimit(searchParams.get("limit"), config.maxLimit); + const limit = parseLimit(searchParams.get("limit")); if (limit) query += ` LIMIT ${limit}`; const page = parsePage(searchParams.get("page")); diff --git a/src/utils.ts b/src/utils.ts index 667df3d..83d4dd5 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -5,15 +5,15 @@ export function parseBlockId(block_id?: string | null) { } export function parseLimit(limit?: string | null | number, defaultLimit?: number) { - let value = 0; // default 0 (no limit) + let value = 1; // default 1 if (defaultLimit) value = defaultLimit; if (limit) { if (typeof limit === "string") value = parseInt(limit); if (typeof limit === "number") value = limit; } - // limit must be between 0 (no limit) and maxLimit - if (value < 0) value = 0; + // limit must be between 1 and maxLimit + if (value <= 0) value = 1; if (value > config.maxLimit) value = config.maxLimit; return value; }