kopia lustrzana https://github.com/bugout-dev/moonstream
Add buttons for control stream.
rodzic
d59084965c
commit
401f12a488
|
@ -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 (
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 ? (
|
||||
<Center>
|
||||
<Stack direction="row" justifyContent="space-between">
|
||||
<Button
|
||||
onClick={() => {
|
||||
setStreamBoundary({
|
||||
start_time: null,
|
||||
end_time: null,
|
||||
include_start: false,
|
||||
include_end: true,
|
||||
next_event_time: null,
|
||||
previous_event_time: null,
|
||||
update: true,
|
||||
});
|
||||
}}
|
||||
variant="outline"
|
||||
colorScheme="suggested"
|
||||
>
|
||||
Refresh to newest
|
||||
</Button>
|
||||
|
||||
{streamBoundary.next_event_time &&
|
||||
streamBoundary.end_time != 0 &&
|
||||
!isLoading ? (
|
||||
<Button
|
||||
onClick={() => {
|
||||
console.log("*********************");
|
||||
console.log("*********************");
|
||||
console.log("*********************");
|
||||
console.log("*** UP ***");
|
||||
console.log("*********************");
|
||||
console.log("*********************");
|
||||
updateStreamBoundaryWith({
|
||||
start_time: streamBoundary.end_time,
|
||||
end_time: streamBoundary.next_event_time,
|
||||
end_time: streamBoundary.next_event_time + 5 * 60,
|
||||
include_start: false,
|
||||
include_end: true,
|
||||
update: true,
|
||||
});
|
||||
}}
|
||||
variant="outline"
|
||||
|
@ -555,10 +555,10 @@ const EntriesNavigation = () => {
|
|||
>
|
||||
Load latest transaction
|
||||
</Button>
|
||||
</Center>
|
||||
) : (
|
||||
"" // 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
|
||||
)}
|
||||
</Stack>
|
||||
{entries.map((entry, idx) => (
|
||||
<StreamEntry
|
||||
key={`entry-list-${idx}`}
|
||||
|
@ -573,27 +573,11 @@ const EntriesNavigation = () => {
|
|||
<Center>
|
||||
<Button
|
||||
onClick={() => {
|
||||
console.log("updateStreamBoundaryWith");
|
||||
console.log("streamBoundary", streamBoundary);
|
||||
console.log(
|
||||
"streamBoundary.previous_event_time",
|
||||
streamBoundary.previous_event_time
|
||||
);
|
||||
console.log(
|
||||
"streamBoundary.start_time",
|
||||
streamBoundary.start_time
|
||||
);
|
||||
console.log("*********************");
|
||||
console.log("*********************");
|
||||
console.log("*********************");
|
||||
console.log("*** DOWN ***");
|
||||
console.log("*********************");
|
||||
console.log("*********************");
|
||||
updateStreamBoundaryWith({
|
||||
start_time: streamBoundary.previous_event_time,
|
||||
end_time: streamBoundary.start_time,
|
||||
start_time: streamBoundary.previous_event_time - 5 * 60,
|
||||
include_start: false,
|
||||
include_end: true,
|
||||
update: true,
|
||||
});
|
||||
|
||||
//fetchPreviousPage();
|
||||
|
|
|
@ -32,15 +32,15 @@ const useJournalEntries = ({
|
|||
|
||||
return {
|
||||
data: [...newEventsList],
|
||||
boundaries: { ...response.data.boundaries },
|
||||
boundaries: { ...response.data.boundaries, update: false },
|
||||
};
|
||||
};
|
||||
|
||||
const { data, isLoading, refetch } = useQuery(
|
||||
["stream", { searchQuery }],
|
||||
["stream", searchQuery],
|
||||
getStream(searchQuery, start_time, end_time, include_start, include_end),
|
||||
{
|
||||
refetchInterval: refreshRate,
|
||||
//refetchInterval: refreshRate,
|
||||
...queryCacheProps,
|
||||
onSuccess: (response) => {
|
||||
// response is object which return condition in getStream
|
||||
|
|
Ładowanie…
Reference in New Issue