Skip to content

Commit

Permalink
Optimize sort query
Browse files Browse the repository at this point in the history
  • Loading branch information
Groxan committed Jul 5, 2020
1 parent 7985d1d commit fbdf185
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Tzkt.Api/Repositories/OperationRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5754,7 +5754,7 @@ public string Pagination(string alias, SortMode sort, int offset, OffsetMode off
if (offset == 0)
{
return $@"
ORDER BY {alias}.""Id"" {sortMode} NULLS LAST
ORDER BY {alias}.""Id"" {sortMode}
LIMIT {limit}";
}

Expand All @@ -5763,18 +5763,18 @@ public string Pagination(string alias, SortMode sort, int offset, OffsetMode off
return sort == SortMode.Ascending
? $@"
AND {alias}.""Id"" > {offset}
ORDER BY {alias}.""Id"" {sortMode} NULLS LAST
ORDER BY {alias}.""Id"" {sortMode}
LIMIT {limit}"
: $@"
AND {alias}.""Id"" < {offset}
ORDER BY {alias}.""Id"" {sortMode} NULLS LAST
ORDER BY {alias}.""Id"" {sortMode}
LIMIT {limit}";
}

var offsetValue = offsetMode == OffsetMode.Page ? limit * offset : offset;

return $@"
ORDER BY {alias}.""Id"" {sortMode} NULLS LAST
ORDER BY {alias}.""Id"" {sortMode}
OFFSET {offsetValue}
LIMIT {limit}";
}
Expand Down

0 comments on commit fbdf185

Please sign in to comment.