Skip to content

Commit d37199c

Browse files
authored
chore: add comments on why we implement the lazy load pagination we way we did (#67)
1 parent 98c005e commit d37199c

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/features/common/constants.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
export const ZERO_ADDRESS = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ'
22
// The default limit when we fetch data from the indexer
3-
// In most places, we use page size 10, 20, 30, 40, 50.
4-
// 100 items will give us at least 2 pages of data.
5-
export const DEFAULT_FETCH_SIZE = 100
3+
// We chose 100 because:
4+
// - In most places, we use page size 10, 20, 30, 40, 50. 100 items will give us at least 2 pages of data.
5+
// - 100 is small enough to not cause performance issues.
6+
// For example, for the account EXECUTOREZZDJN3NFLVZNXE7UZKCERNFC6FD7SBXMVKASKRF4ZASJKN5BE
7+
// the response size of fetching 100 items is 180Kb (Gzipped), which is ok.
8+
// if we up it to 200, the response is 400Kb and can cause performance issues.
9+
export const DEFAULT_FETCH_SIZE = 200

src/features/common/data/lazy-load-pagination.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ export type ViewModelPage<TViewModel> = {
2020

2121
type FetchRawData<TData> = (nextPageToken?: string) => Atom<Promise<LoadDataResponse<TData>>>
2222

23+
// We had to implement this way, instead of fetching items page per page
24+
// because the indexer doesn't return a deterministic number of items
25+
// it supports "limit" param, but that means the upper limit.
26+
// for example, when getting transactions with limit 10, it a maximum of 10 items, sometimes it returns 4 or 5 items
2327
type CreateLoadableViewModelPageAtomInput<TRawData, TViewModel> = {
2428
fetchRawData: FetchRawData<TRawData>
2529
createViewModelPageAtom: (

0 commit comments

Comments
 (0)