pageSize()

Modifies the rendered page size of a Set in a query result.

Lazy loading:

Yes

Signature

pageSize(size: Int): Set<A>

Description

The pageSize() method modifies the page size of a Set in a query result. It limits the size of each page to a maximum size number of items.

pageSize() renders the calling set as a Set value that includes the first page of results and an after cursor for fetching subsequent pages. Fauna’s official drivers include a paginate method to handle the cursor and asynchronously iterate over the entire set. pageSize() controls the page size used during iteration.

Lazy loading

pageSize() uses lazy loading. It only fetches results to return a query response or to call a method that uses eager loading. It does not perform any reads on the underlying Set's data.

Method chaining

pageSize() only changes the page size when rendering a Set. Methods chained to pageSize(), such as forEach(), access the entire calling Set, not a page of results. To get a subset of a Set, use take() instead.

Differences with paginate()

pageSize() is similar to paginate(). In most cases, you should use pageSize(). pageSize() tends to produce faster queries with less compute.

Major differences between the methods include:

after cursor

The after pagination cursor is stable in the sense that pagination through a set is done for a fixed snapshot time, giving you a view of your data as it existed across the whole set at the instant you started paginating. For example, given set [a, b, c] when you start paginating, one item at a time, even if you delete item c after you started reading the set, item c is returned.

The exception is if the history is no longer available for the deleted item because history_days is set to the default value of 0 or is less than the minimum valid time needed. In that case, the deleted item is not returned with the paginated results and an error is returned:
Requested timestamp <time> less than minimum allowed timestamp..

A cursor is valid for history_days plus 15 minutes.

Parameters

Parameter Type Required Description

size

Int

Yes

Number of Set values to include in the returned page. The size parameter must be in the range 1 to 16000.

Return value

Type Description

Set

Set that includes the following field:

after

(optional) Cursor pointing to next page when more pages exist. The cursor is valid for history_days plus 15 minutes.

Examples

Product.sortedByPriceHighToLow()
  .pageSize(2)
{
  data: [
    {
      id: "393466615439556672",
      coll: Product,
      ts: Time("2024-03-27T00:04:15.593Z"),
      name: "pinata",
      ...
    },
    ...
  ],
  after: "hdWCxmd..."
}

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!