Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/carterqw2/query-pagination' into…
Browse files Browse the repository at this point in the history
… dhutch/fixes
  • Loading branch information
rkachowski committed Jun 12, 2023
2 parents 646199a + 733c931 commit af00b42
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion apps/block_scout_web/.iex.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ defmodule Clabs.Debug do

def token_tx_for_valora_address do
{:ok,hsh} = Address.cast("0x6131a6d616a4be3737b38988847270a64bc10caa")
Explorer.GraphQL.token_txtransfers_query_for_address(hsh, 26)
Explorer.GraphQL.token_txtransfers_query_for_address(hsh, 26, 0)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ defmodule BlockScoutWeb.Resolvers.TokenTransferTx do
alias Absinthe.Relay.Connection
alias Explorer.{GraphQL, Repo}

def get_by(_, %{address_hash: address_hash, first: first} = args, _) do
def get_by(_, %{address_hash: address_hash, first: limit} = args, _) do
connection_args = Map.take(args, [:after, :before, :first, :last])

offset = case Connection.offset(args) do
{:ok, offset} when is_integer(offset) -> offset
_ -> 0
end

address_hash
|> GraphQL.token_txtransfers_query_for_address(first)
|> GraphQL.token_txtransfers_query_for_address(offset, limit)
|> Connection.from_query(&Repo.all/1, connection_args, options(args))
end

Expand Down
11 changes: 5 additions & 6 deletions apps/explorer/lib/explorer/graphql.ex
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,9 @@ defmodule Explorer.GraphQL do
)
end

def token_txtransfers_query_for_address(address_hash, first) do
tt_limit = first * 2
def token_txtransfers_query_for_address(address_hash, offset, limit) do
page = floor(offset/limit) + 1
growing_limit = limit * (page + 1)

tokens =
from(
Expand All @@ -254,8 +255,7 @@ defmodule Explorer.GraphQL do
desc: tt.from_address_hash,
desc: tt.to_address_hash
],
limit: ^tt_limit,
offset: 0
limit: ^growing_limit
)

from(
Expand All @@ -282,8 +282,7 @@ defmodule Explorer.GraphQL do
input: tx.input,
nonce: tx.nonce,
block_number: tt.block_number
},
limit: ^first
}
)
|> order_by([transaction: t],
desc: t.block_number,
Expand Down

0 comments on commit af00b42

Please sign in to comment.