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

Commit

Permalink
perf(wallet): bound transaction loading to page size
Browse files Browse the repository at this point in the history
  • Loading branch information
mrfelton committed Oct 10, 2020
1 parent afb20f3 commit cecad88
Showing 1 changed file with 31 additions and 16 deletions.
47 changes: 31 additions & 16 deletions renderer/reducers/activity/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { grpc } from 'workers'
import combinePaginators from '@zap/utils/pagination'

import { mainLog } from '@zap/utils/log'
export const months = [
'Jan',
'Feb',
Expand Down Expand Up @@ -155,21 +155,36 @@ export const createActivityPaginator = () => {
}

const fetchTransactions = async (pageSize, offset, blockHeight) => {
// Lets load 10x more bloks that page size is set to since blocks only cover a 10 minute period.
const vPagesize = pageSize * 5

// Determine start point.
const firstStart = blockHeight - vPagesize
const nextStart = offset - vPagesize
const startHeight = offset === 0 ? firstStart : nextStart

// Determine end height.
const endHeight = offset || -1
const { transactions } = await grpc.services.Lightning.getTransactions({
startHeight,
endHeight,
})
return { items: transactions, offset: startHeight }
// Lets load 25x more bloks than page size is set to since blocks only cover a 10 minute period.
// with a 50 item page size, that would mean loading transactions in chunks of about 10 days.
var vPageSize = pageSize * 25

let count = 0
let items = []
var hasItems = !offset || 500000 < offset
while (hasItems && count < pageSize) {
// Determine start point.
const firstStart = blockHeight - vPageSize
const nextStart = offset - vPageSize
const startHeight = offset === 0 ? firstStart : nextStart

// Determine end height.
const endHeight = offset || -1

// Load items.
mainLog.info(`Loading transactions from block height ${startHeight} to ${endHeight}`)
const { transactions } = await grpc.services.Lightning.getTransactions({
startHeight,
endHeight,
})
mainLog.info(`Loaded ${transactions.length} transactions from block height ${startHeight} to ${endHeight}`)
count += transactions.length
items = items.concat(transactions);
offset = startHeight
}
mainLog.info(`Loaded ${items.length} transactions in total for paginator`)

return { items : items.slice(0, vPageSize), offset }
}

const getTimestamp = item =>
Expand Down

0 comments on commit cecad88

Please sign in to comment.