Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
perf(wallet): insert fetched activity early
Browse files Browse the repository at this point in the history
  • Loading branch information
mrfelton committed Oct 25, 2020
1 parent 56cf680 commit e1dfefd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
11 changes: 8 additions & 3 deletions renderer/reducers/activity/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,16 @@ let loadedPages = 0
* getPaginator - Returns current activity paginator object. This acts as a singleton
* and creates paginator if it's not initialized.
*
* @param {Function} dispatch Reduc dispatcher.
* @returns {Function} Paginator
*/
export const getPaginator = () => {
export const getPaginator = dispatch => {
if (!paginator) {
paginator = createActivityPaginator()
paginator = createActivityPaginator({
invoiceHandler: items => dispatch(receiveInvoices(items)),
paymentHandler: items => dispatch(receivePayments(items)),
transactionHandler: items => dispatch(receiveTransactions(items)),
})
}
return paginator
}
Expand Down Expand Up @@ -264,7 +269,7 @@ export const loadPage = (reload = false) => async (dispatch, getState) => {
await dispatch(fetchInfo())
const config = settingsSelectors.currentConfig(getState())
const blockHeight = infoSelectors.blockHeight(getState())
const thisPaginator = getPaginator()
const thisPaginator = getPaginator(dispatch)

if (reload || hasNextPage(getState())) {
const { pageSize } = config.activity
Expand Down
11 changes: 10 additions & 1 deletion renderer/reducers/activity/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,20 @@ export const prepareData = (data, searchText) => {
/**
* createActivityPaginator - Creates activity paginator object.
*
* @param {object} options Options.
* @param {Function} options.invoiceHandler Invoice handler. Called when new invoices are fetched.
* @param {Function} options.paymentHandler Payment handler. Called when new payments are fetched.
* @param {Function} options.transactionHandler Transaction handler. Called when new transactions are fetched.
* @returns {Function} Paginator
*/
export const createActivityPaginator = () => {
export const createActivityPaginator = ({ invoiceHandler, paymentHandler, transactionHandler }) => {
const fetchInvoices = async (pageSize, offset) => {
const { invoices, firstIndexOffset } = await grpc.services.Lightning.listInvoices({
numMaxInvoices: pageSize,
indexOffset: offset,
reversed: true,
})
invoiceHandler(invoices)
return { items: invoices, offset: parseInt(firstIndexOffset || 0, 10) }
}

Expand All @@ -152,6 +157,7 @@ export const createActivityPaginator = () => {
indexOffset: offset,
reversed: true,
})
paymentHandler(payments)
return { items: payments, offset: parseInt(firstIndexOffset || 0, 10) }
}

Expand Down Expand Up @@ -183,10 +189,13 @@ export const createActivityPaginator = () => {
mainLog.info(
`Loaded ${transactions.length} transactions from block height ${startHeight} to ${endHeight}`
)
transactionHandler(transactions)

count += transactions.length
items = items.concat(transactions)

// Lightning didn't exist prior to this so no point in going back further.
// TOOO: Figure out the wallet birthday and stop at that point.
hasMoreItems = startHeight > 500000 && count < pageSize
if (hasMoreItems) {
// Determine next end height.
Expand Down

0 comments on commit e1dfefd

Please sign in to comment.