diff --git a/backend/moonstream/actions.py b/backend/moonstream/actions.py index 8e29aa95..7d4449e8 100644 --- a/backend/moonstream/actions.py +++ b/backend/moonstream/actions.py @@ -14,7 +14,7 @@ from sqlalchemy.sql.expression import desc, false from . import data -from .settings import DEFAULT_PAGE_SIZE +from .settings import DEFAULT_STREAM_TIMEINTERVAL logger = logging.getLogger(__name__) @@ -107,10 +107,64 @@ async def get_transaction_in_blocks( EthereumBlock.timestamp <= start_time ) + print(start_time) + + future_last_transaction = ( + db_session.query( + EthereumTransaction.hash, + EthereumTransaction.block_number, + EthereumTransaction.from_address, + EthereumTransaction.to_address, + EthereumTransaction.gas, + EthereumTransaction.gas_price, + EthereumTransaction.input, + EthereumTransaction.nonce, + EthereumTransaction.value, + EthereumBlock.timestamp.label("timestamp"), + ) + .join(EthereumBlock) + .filter(filters) + .filter(EthereumBlock.timestamp > start_time) + .order_by(text("timestamp desc")) + .limit(1) + ).one_or_none() + start_time = False + + if future_last_transaction: + next_future_timestamp = future_last_transaction[-1] + else: + next_future_timestamp = None + if end_time: ethereum_transactions = ethereum_transactions.filter( EthereumBlock.timestamp >= end_time ) + print("end_time", end_time) + next_last_transaction = ( + db_session.query( + EthereumTransaction.hash, + EthereumTransaction.block_number, + EthereumTransaction.from_address, + EthereumTransaction.to_address, + EthereumTransaction.gas, + EthereumTransaction.gas_price, + EthereumTransaction.input, + EthereumTransaction.nonce, + EthereumTransaction.value, + EthereumBlock.timestamp.label("timestamp"), + ) + .join(EthereumBlock) + .filter(filters) + .filter(1628263498 > EthereumBlock.timestamp) + .order_by(text("timestamp desc")) + .limit(1) + ).one_or_none() + start_time = False + print("next_last_transaction_timestamp", next_last_transaction) + if next_last_transaction: + next_last_transaction_timestamp = next_last_transaction[-1] + else: + next_last_transaction_timestamp = None print(f"count: {ethereum_transactions.count()}") @@ -166,7 +220,12 @@ async def get_transaction_in_blocks( ) ) - return response, start_time, end_time + return ( + response, + end_time, + next_future_timestamp, + next_last_transaction_timestamp, + ) def database_search_query(q: str, allowed_addresses: List[str]): diff --git a/backend/moonstream/data.py b/backend/moonstream/data.py index 75d03f3a..00936621 100644 --- a/backend/moonstream/data.py +++ b/backend/moonstream/data.py @@ -131,6 +131,8 @@ class EthereumTransactionResponse(BaseModel): stream: List[EthereumTransactionItem] start_time: int end_time: int + next_future_timestamp: Optional[int] = None + next_past_transaction_timestamp: Optional[int] = None class TxinfoEthereumBlockchainRequest(BaseModel): diff --git a/backend/moonstream/routes/streams.py b/backend/moonstream/routes/streams.py index b52aaabb..7b91cf46 100644 --- a/backend/moonstream/routes/streams.py +++ b/backend/moonstream/routes/streams.py @@ -92,8 +92,9 @@ async def search_transactions( print("address_to_subscriptions") ( transactions_in_blocks, - first_item_time, - last_item_time, + end_time, + next_future_timestamp, + next_last_transaction_timestamp, ) = await actions.get_transaction_in_blocks( db_session=db_session, query=q, @@ -104,6 +105,11 @@ async def search_transactions( transactions.extend(transactions_in_blocks) + return data.EthereumTransactionResponse( - stream=transactions, start_time=first_item_time, end_time=last_item_time + stream=transactions, + next_future_timestamp=next_future_timestamp, + next_past_transaction_timestamp=next_last_transaction_timestamp, + end_time=end_time, + start_time=start_time, ) diff --git a/backend/moonstream/settings.py b/backend/moonstream/settings.py index ee7603c5..50dd4ea6 100644 --- a/backend/moonstream/settings.py +++ b/backend/moonstream/settings.py @@ -40,4 +40,4 @@ for path in MOONSTREAM_OPENAPI_LIST: DOCS_PATHS[f"/{path}/{DOCS_TARGET_PATH}"] = "GET" DOCS_PATHS[f"/{path}/{DOCS_TARGET_PATH}/openapi.json"] = "GET" -DEFAULT_PAGE_SIZE = 10 +DEFAULT_STREAM_TIMEINTERVAL = 60 * 60 diff --git a/frontend/src/components/EntriesNavigation.js b/frontend/src/components/EntriesNavigation.js index 90277207..0e6592fc 100644 --- a/frontend/src/components/EntriesNavigation.js +++ b/frontend/src/components/EntriesNavigation.js @@ -78,22 +78,40 @@ const EntriesNavigation = () => { const loadMoreButtonRef = useRef(null); - const { fetchMore, isFetchingMore, canFetchMore, EntriesPages, isLoading } = - useStream({ - pageSize, - refreshRate: 1500, - searchQuery: ui.searchTerm, - enabled: isStreamOn, - isContent: false, - }); + // const { + // fetchPreviousPage, + // isFetchingMore, + // hasPreviousPage, + // EntriesPages, + // isLoading, + // hasNextPage, + // fetchNextPage, + // } = useStream({ + // pageSize, + // refreshRate: 1500, + // searchQuery: ui.searchTerm, + // enabled: isStreamOn, + // isContent: false, + // }); + + const { EntriesPages, isLoading, refetch } = useStream({ + refreshRate: 1500, + searchQuery: ui.searchTerm, + start_time, + end_time, + include_start, + include_end, + enabled: isStreamOn, + isContent: false, + }); const handleScroll = ({ currentTarget }) => { if ( currentTarget.scrollTop + currentTarget.clientHeight >= 0.5 * currentTarget.scrollHeight ) { - if (!isFetchingMore && canFetchMore) { - fetchMore(); + if (!isLoading && hasPreviousPage) { + fetchPreviousPage(); } } }; @@ -439,10 +457,10 @@ const EntriesNavigation = () => { filterConstants={{ DIRECTIONS, CONDITION, FILTER_TYPES }} /> ))} - {canFetchMore && !isFetchingMore && ( + {hasPreviousPage && !isFetchingMore && (
)} - {canFetchMore && isFetchingMore && ( + {hasPreviousPage && isFetchingMore && (