diff --git a/backend/moonstream/actions.py b/backend/moonstream/actions.py index c50ecad7..c6cd028d 100644 --- a/backend/moonstream/actions.py +++ b/backend/moonstream/actions.py @@ -86,14 +86,16 @@ async def get_transaction_in_blocks( # If not start_time and end_time not present # Get latest transaction - if boundaries.start_time == 0 and boundaries.end_time == 0: + if boundaries.end_time == 0: ethereum_transaction_start_point = ( ethereum_transactions_in_subscriptions.order_by( text("timestamp desc") ).limit(1) ).one_or_none() - boundaries.end_time = 0 - boundaries.start_time = ethereum_transaction_start_point[-1] + boundaries.end_time = ethereum_transaction_start_point[-1] + boundaries.start_time = ( + ethereum_transaction_start_point[-1] - DEFAULT_STREAM_TIMEINTERVAL + ) if boundaries.start_time != 0 and boundaries.end_time != 0: if boundaries.start_time > boundaries.end_time: @@ -102,8 +104,30 @@ async def get_transaction_in_blocks( boundaries.start_time, ) - if boundaries.start_time: + if boundaries.end_time: ethereum_transactions = ethereum_transactions_in_subscriptions.filter( + include_or_not_lower( + EthereumBlock.timestamp, boundaries.include_end, boundaries.end_time + ) + ) + + next_transaction = ( + ethereum_transactions_in_subscriptions.filter( + EthereumBlock.timestamp > boundaries.end_time + ) + .order_by(text("timestamp ASC")) + .limit(1) + ) + + next_transaction = next_transaction.one_or_none() + + if next_transaction: + boundaries.next_event_time = next_transaction[-1] + else: + boundaries.next_event_time = None + + if boundaries.start_time: + ethereum_transactions = ethereum_transactions.filter( include_or_not_grater( EthereumBlock.timestamp, boundaries.include_start, @@ -118,41 +142,11 @@ async def get_transaction_in_blocks( .order_by(text("timestamp desc")) .limit(1) ).one_or_none() - # start_time = False if previous_transaction: boundaries.previous_event_time = previous_transaction[-1] else: - boundaries.previous_event_time = 0 - else: - if boundaries.end_time: - boundaries.start_time = boundaries.end_time - DEFAULT_STREAM_TIMEINTERVAL - - if boundaries.end_time: - ethereum_transactions = ethereum_transactions.filter( - include_or_not_lower( - EthereumBlock.timestamp, boundaries.include_end, boundaries.end_time - ) - ) - print("end_time", boundaries.end_time) - next_transaction = ( - ethereum_transactions_in_subscriptions.filter( - EthereumBlock.timestamp > boundaries.end_time - ) - .order_by(text("timestamp ASC")) - .limit(1) - ) - - next_transaction = next_transaction.one_or_none() - - if next_transaction: - boundaries.next_event_time = next_transaction[-1] - else: - boundaries.next_event_time = 0 - else: - boundaries.end_time = 0 - - print(f"count: {ethereum_transactions.count()}") + boundaries.previous_event_time = None response = [] for ( diff --git a/backend/moonstream/settings.py b/backend/moonstream/settings.py index 50dd4ea6..47ddff2f 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_STREAM_TIMEINTERVAL = 60 * 60 +DEFAULT_STREAM_TIMEINTERVAL = 5 * 60 diff --git a/frontend/src/components/EntriesNavigation.js b/frontend/src/components/EntriesNavigation.js index 1dfe1c0c..8422ad9e 100644 --- a/frontend/src/components/EntriesNavigation.js +++ b/frontend/src/components/EntriesNavigation.js @@ -30,6 +30,7 @@ import { Tag, TagLabel, TagCloseButton, + Stack, Spacer, useBoolean, } from "@chakra-ui/react"; @@ -82,9 +83,10 @@ const EntriesNavigation = () => { start_time: null, end_time: null, include_start: false, - include_end: false, + include_end: true, next_event_time: null, previous_event_time: null, + update: false, }); const updateStreamBoundaryWith = (pageBoundary) => { @@ -105,71 +107,49 @@ const EntriesNavigation = () => { // setStreamBoundary(pageBoundary) // return pageBoundary // } - console.log("start_time"); - console.log( - "pageBoundary.start_time <= newBoundary.start_time", - pageBoundary.start_time <= newBoundary.start_time - ); if ( !newBoundary.start_time || (pageBoundary.start_time && - pageBoundary.start_time <= newBoundary.start_time) || - ((pageBoundary.start_time > streamBoundary.end_time || - (pageBoundary.start_time == streamBoundary.end_time && - !streamBoundary.include_end)) && - pageBoundary.end_time > streamBoundary.end_time) || - pageBoundary.end_time == 0 // meen go with server + pageBoundary.start_time <= newBoundary.start_time) ) { newBoundary.start_time = pageBoundary.start_time; newBoundary.include_start = newBoundary.include_start || pageBoundary.include_start; } + newBoundary.include_start = + newBoundary.include_start || pageBoundary.include_start; if ( !newBoundary.end_time || - (pageBoundary.end_time && - pageBoundary.end_time >= newBoundary.end_time) || - ((pageBoundary.end_time < streamBoundary.start_time || - (pageBoundary.end_time == streamBoundary.start_time && - !streamBoundary.include_start)) && - pageBoundary.start_time < streamBoundary.start_time) + (pageBoundary.end_time && pageBoundary.end_time >= newBoundary.end_time) ) { newBoundary.end_time = pageBoundary.end_time; newBoundary.include_end = newBoundary.include_end || pageBoundary.include_end; } - newBoundary.next_event_time = pageBoundary.next_event_time; - newBoundary.previous_event_time = pageBoundary.previous_event_time; - // console.log( - // "pageBoundary.next_event_time < newBoundary.next_event_time && pageBoundary.end_time <= streamBoundary.start_tim", - // pageBoundary.next_event_time < newBoundary.next_event_time && - // pageBoundary.end_time <= streamBoundary.start_tim - // ); - // if ( - // !newBoundary.next_event_time || - // pageBoundary.next_event_time == 0 || - // (pageBoundary.next_event_time && - // pageBoundary.next_event_time > newBoundary.next_event_time) || - // (pageBoundary.next_event_time < newBoundary.next_event_time && - // pageBoundary.end_time <= streamBoundary.start_time) - // ) { - // newBoundary.next_event_time = pageBoundary.next_event_time; - // } + newBoundary.include_end = + newBoundary.include_end || pageBoundary.include_end; - // if ( - // !newBoundary.previous_event_time || - // pageBoundary.previous_event_time == 0 || - // (pageBoundary.previous_event_time && - // pageBoundary.previous_event_time < newBoundary.previous_event_time) || - // (pageBoundary.previous_event_time > newBoundary.previous_event_time && - // pageBoundary.start_time >= streamBoundary.end_time) || - // pageBoundary.end_time == 0 - // ) { - // newBoundary.previous_event_time = pageBoundary.previous_event_time; - // } + if ( + !newBoundary.next_event_time || + pageBoundary.next_event_time == 0 || + (pageBoundary.next_event_time && + pageBoundary.next_event_time > newBoundary.next_event_time) + ) { + newBoundary.next_event_time = pageBoundary.next_event_time; + } + if ( + !newBoundary.previous_event_time || + pageBoundary.previous_event_time == 0 || + (pageBoundary.previous_event_time && + pageBoundary.previous_event_time < newBoundary.previous_event_time) + ) { + newBoundary.previous_event_time = pageBoundary.previous_event_time; + } + newBoundary.update = pageBoundary.update; setStreamBoundary(newBoundary); return newBoundary; }; @@ -200,6 +180,14 @@ const EntriesNavigation = () => { // } // }; + useEffect(() => { + if (EntriesPages && !isLoading && streamBoundary.update) { + console.log("streamBoundary.update", streamBoundary.update); + streamBoundary.update = false; + refetch(); + } + }, [streamBoundary]); + const setFilterProps = useCallback( (filterIdx, props) => { const newFilterProps = [...newFilterState]; @@ -531,23 +519,35 @@ const EntriesNavigation = () => { w="100%" //onScroll={(e) => handleScroll(e)} > - {streamBoundary.next_event_time && - streamBoundary.end_time != 0 && - !isLoading ? ( -
+ + + + {streamBoundary.next_event_time && + streamBoundary.end_time != 0 && + !isLoading ? ( -
- ) : ( - "" // some strange behaivior without else condition return 0 wich can see on frontend page - )} + ) : ( + "" // some strange behaivior without else condition return 0 wich can see on frontend page + )} + {entries.map((entry, idx) => ( {