CodeChain-io/codechain-indexer

Use "last seen item" to paginate query results

Closed this issue · 4 comments

We are using SKIP for the pagination feature. SKIP causes performance issues. Let's use "last seen item" instead.

All APIs that return a list will change the response format.

// BEFORE
[1,2,3]

// AFTER
{
  lastEvalulatedKey: "SomeKeyValue",
  hasNextPage: true,
  data: [1,2,3]
}

lastEvaulatedKey will be stringified JSON value.
In the UTXO API, lastEvaluatedKey will be "[${blockNumber}, ${transactionIndex}, ${transactionOutputIndex}]"

Clients must not parse the lastEvaluatedKey. They should pass the lastEvaluatedKey when they request the next page.

// For example
{
  data: [..., {
    ...,
    blockNumber: 46,
    transactionIndex: 0,
    transactionOutputIndex: 2
  }],
  hasNextPage: true,
  lastEvaluatedKey: "[46, 0, 2]"
}

We will add firstEvaluatedKey and hasPreviousPage.

DONE