Skip to content

Commit

Permalink
Set min pagination limit for tokens endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Groxan committed Feb 7, 2024
1 parent e18fef4 commit 9b91ec0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
16 changes: 8 additions & 8 deletions Tzkt.Api/Repositories/TokensRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ async Task<IEnumerable<dynamic>> QueryTokensAsync(TokenFilter filter, Pagination
"lastLevel" => (@"""LastLevel""", @"""LastLevel"""),
"metadata" => (@"""Metadata""", @"""Metadata"""),
_ => TryMetaSort(x)
});
}, @"""Id""", 100);

using var db = GetConnection();
return await db.QueryAsync(sql.Query, sql.Params);
return (await db.QueryAsync(sql.Query, sql.Params)).Take(pagination.limit);
}

public async Task<int> GetTokensCount(TokenFilter filter)
Expand Down Expand Up @@ -411,9 +411,9 @@ LIMIT 1
"lastLevel" => (new string[1] { @"tb.""LastLevel""" }, @"tb.""LastLevel"""),
"token.metadata" => (new string[1] { @"t.""Metadata""" }, @"t.""Metadata"""),
_ => TryMetaSort(x)
}, @"tb.""Id""");
}, @"tb.""Id""", 100);

return await db.QueryAsync(sql.Query, sql.Params);
return (await db.QueryAsync(sql.Query, sql.Params)).Take(pagination.limit);
}

public async Task<int> GetTokenBalancesCount(TokenBalanceFilter filter)
Expand Down Expand Up @@ -691,10 +691,10 @@ async Task<IEnumerable<dynamic>> QueryTokenTransfersAsync(TokenTransferFilter fi
"amount" => (@"tr.""Amount""::numeric", @"tr.""Amount""::numeric"),
"token.metadata" => (@"t.""Metadata""", @"t.""Metadata"""),
_ => TryMetaSort(x)
}, @"tr.""Id""");
}, @"tr.""Id""", 100);

using var db = GetConnection();
return await db.QueryAsync(sql.Query, sql.Params);
return (await db.QueryAsync(sql.Query, sql.Params)).Take(pagination.limit);
}

public async Task<int> GetTokenTransfersCount(TokenTransferFilter filter)
Expand Down Expand Up @@ -981,10 +981,10 @@ async Task<IEnumerable<dynamic>> QueryHistoricalTokenBalancesAsync(int level, To
"balance" => (@"""Balance""::numeric", @"""Balance""::numeric"),
"token.metadata" => (@"t.""Metadata""", @"t.""Metadata"""),
_ => TryMetaSort(x)
}, @"tb.""Id""");
}, @"tb.""Id""", 100);

using var db = GetConnection();
return await db.QueryAsync(sql.Query, sql.Params);
return (await db.QueryAsync(sql.Query, sql.Params)).Take(pagination.limit);
}

public async Task<IEnumerable<TokenBalanceShort>> GetHistoricalTokenBalances(int level, TokenBalanceShortFilter filter, Pagination pagination)
Expand Down
8 changes: 4 additions & 4 deletions Tzkt.Api/Utils/SqlBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1826,7 +1826,7 @@ public SqlBuilder FilterA(string column, TimestampParameter value, Func<string,
return this;
}

public SqlBuilder Take(Pagination pagination, Func<string, (string, string)> map, string id = @"""Id""")
public SqlBuilder Take(Pagination pagination, Func<string, (string, string)> map, string id = @"""Id""", int minLimit = 0)
{
var sortAsc = true;
var sortColumn = id;
Expand Down Expand Up @@ -1874,12 +1874,12 @@ public SqlBuilder Take(Pagination pagination, Func<string, (string, string)> map
}

if (pagination.limit != -1)
Builder.AppendLine($"LIMIT {pagination.limit}");
Builder.AppendLine($"LIMIT {Math.Max(pagination.limit, minLimit)}");

return this;
}

public SqlBuilder Take(Pagination pagination, Func<string, (string[], string)> map, string id = @"""Id""")
public SqlBuilder Take(Pagination pagination, Func<string, (string[], string)> map, string id = @"""Id""", int minLimit = 0)
{
var sortAsc = true;
var sortColumns = new string[1] { id };
Expand Down Expand Up @@ -1930,7 +1930,7 @@ public SqlBuilder Take(Pagination pagination, Func<string, (string[], string)> m
}

if (pagination.limit != -1)
Builder.AppendLine($"LIMIT {pagination.limit}");
Builder.AppendLine($"LIMIT {Math.Max(pagination.limit, minLimit)}");

return this;
}
Expand Down

0 comments on commit 9b91ec0

Please sign in to comment.