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
|
# If not start_time and end_time not present
|
||||||
# Get latest transaction
|
# Get latest transaction
|
||||||
if boundaries.start_time == 0 and boundaries.end_time == 0:
|
if boundaries.end_time == 0:
|
||||||
ethereum_transaction_start_point = (
|
ethereum_transaction_start_point = (
|
||||||
ethereum_transactions_in_subscriptions.order_by(
|
ethereum_transactions_in_subscriptions.order_by(
|
||||||
text("timestamp desc")
|
text("timestamp desc")
|
||||||
).limit(1)
|
).limit(1)
|
||||||
).one_or_none()
|
).one_or_none()
|
||||||
boundaries.end_time = 0
|
boundaries.end_time = ethereum_transaction_start_point[-1]
|
||||||
boundaries.start_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 != 0 and boundaries.end_time != 0:
|
||||||
if boundaries.start_time > boundaries.end_time:
|
if boundaries.start_time > boundaries.end_time:
|
||||||
|
@ -102,8 +104,30 @@ async def get_transaction_in_blocks(
|
||||||
boundaries.start_time,
|
boundaries.start_time,
|
||||||
)
|
)
|
||||||
|
|
||||||
if boundaries.start_time:
|
if boundaries.end_time:
|
||||||
ethereum_transactions = ethereum_transactions_in_subscriptions.filter(
|
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(
|
include_or_not_grater(
|
||||||
EthereumBlock.timestamp,
|
EthereumBlock.timestamp,
|
||||||
boundaries.include_start,
|
boundaries.include_start,
|
||||||
|
@ -118,41 +142,11 @@ async def get_transaction_in_blocks(
|
||||||
.order_by(text("timestamp desc"))
|
.order_by(text("timestamp desc"))
|
||||||
.limit(1)
|
.limit(1)
|
||||||
).one_or_none()
|
).one_or_none()
|
||||||
# start_time = False
|
|
||||||
|
|
||||||
if previous_transaction:
|
if previous_transaction:
|
||||||
boundaries.previous_event_time = previous_transaction[-1]
|
boundaries.previous_event_time = previous_transaction[-1]
|
||||||
else:
|
else:
|
||||||
boundaries.previous_event_time = 0
|
boundaries.previous_event_time = None
|
||||||
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()}")
|
|
||||||
|
|
||||||
response = []
|
response = []
|
||||||
for (
|
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}"] = "GET"
|
||||||
DOCS_PATHS[f"/{path}/{DOCS_TARGET_PATH}/openapi.json"] = "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,
|
Tag,
|
||||||
TagLabel,
|
TagLabel,
|
||||||
TagCloseButton,
|
TagCloseButton,
|
||||||
|
Stack,
|
||||||
Spacer,
|
Spacer,
|
||||||
useBoolean,
|
useBoolean,
|
||||||
} from "@chakra-ui/react";
|
} from "@chakra-ui/react";
|
||||||
|
@ -82,9 +83,10 @@ const EntriesNavigation = () => {
|
||||||
start_time: null,
|
start_time: null,
|
||||||
end_time: null,
|
end_time: null,
|
||||||
include_start: false,
|
include_start: false,
|
||||||
include_end: false,
|
include_end: true,
|
||||||
next_event_time: null,
|
next_event_time: null,
|
||||||
previous_event_time: null,
|
previous_event_time: null,
|
||||||
|
update: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const updateStreamBoundaryWith = (pageBoundary) => {
|
const updateStreamBoundaryWith = (pageBoundary) => {
|
||||||
|
@ -105,71 +107,49 @@ const EntriesNavigation = () => {
|
||||||
// setStreamBoundary(pageBoundary)
|
// setStreamBoundary(pageBoundary)
|
||||||
// return pageBoundary
|
// return pageBoundary
|
||||||
// }
|
// }
|
||||||
console.log("start_time");
|
|
||||||
console.log(
|
|
||||||
"pageBoundary.start_time <= newBoundary.start_time",
|
|
||||||
pageBoundary.start_time <= newBoundary.start_time
|
|
||||||
);
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!newBoundary.start_time ||
|
!newBoundary.start_time ||
|
||||||
(pageBoundary.start_time &&
|
(pageBoundary.start_time &&
|
||||||
pageBoundary.start_time <= newBoundary.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
|
|
||||||
) {
|
) {
|
||||||
newBoundary.start_time = pageBoundary.start_time;
|
newBoundary.start_time = pageBoundary.start_time;
|
||||||
newBoundary.include_start =
|
newBoundary.include_start =
|
||||||
newBoundary.include_start || pageBoundary.include_start;
|
newBoundary.include_start || pageBoundary.include_start;
|
||||||
}
|
}
|
||||||
|
newBoundary.include_start =
|
||||||
|
newBoundary.include_start || pageBoundary.include_start;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!newBoundary.end_time ||
|
!newBoundary.end_time ||
|
||||||
(pageBoundary.end_time &&
|
(pageBoundary.end_time && pageBoundary.end_time >= newBoundary.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)
|
|
||||||
) {
|
) {
|
||||||
newBoundary.end_time = pageBoundary.end_time;
|
newBoundary.end_time = pageBoundary.end_time;
|
||||||
newBoundary.include_end =
|
newBoundary.include_end =
|
||||||
newBoundary.include_end || pageBoundary.include_end;
|
newBoundary.include_end || pageBoundary.include_end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newBoundary.include_end =
|
||||||
|
newBoundary.include_end || pageBoundary.include_end;
|
||||||
|
|
||||||
|
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;
|
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.previous_event_time = pageBoundary.previous_event_time;
|
||||||
|
}
|
||||||
// console.log(
|
newBoundary.update = pageBoundary.update;
|
||||||
// "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;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
// }
|
|
||||||
|
|
||||||
setStreamBoundary(newBoundary);
|
setStreamBoundary(newBoundary);
|
||||||
return 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(
|
const setFilterProps = useCallback(
|
||||||
(filterIdx, props) => {
|
(filterIdx, props) => {
|
||||||
const newFilterProps = [...newFilterState];
|
const newFilterProps = [...newFilterState];
|
||||||
|
@ -531,23 +519,35 @@ const EntriesNavigation = () => {
|
||||||
w="100%"
|
w="100%"
|
||||||
//onScroll={(e) => handleScroll(e)}
|
//onScroll={(e) => handleScroll(e)}
|
||||||
>
|
>
|
||||||
|
<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.next_event_time &&
|
||||||
streamBoundary.end_time != 0 &&
|
streamBoundary.end_time != 0 &&
|
||||||
!isLoading ? (
|
!isLoading ? (
|
||||||
<Center>
|
|
||||||
<Button
|
<Button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
console.log("*********************");
|
|
||||||
console.log("*********************");
|
|
||||||
console.log("*********************");
|
|
||||||
console.log("*** UP ***");
|
|
||||||
console.log("*********************");
|
|
||||||
console.log("*********************");
|
|
||||||
updateStreamBoundaryWith({
|
updateStreamBoundaryWith({
|
||||||
start_time: streamBoundary.end_time,
|
end_time: streamBoundary.next_event_time + 5 * 60,
|
||||||
end_time: streamBoundary.next_event_time,
|
|
||||||
include_start: false,
|
include_start: false,
|
||||||
include_end: true,
|
include_end: true,
|
||||||
|
update: true,
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
variant="outline"
|
variant="outline"
|
||||||
|
@ -555,10 +555,10 @@ const EntriesNavigation = () => {
|
||||||
>
|
>
|
||||||
Load latest transaction
|
Load latest transaction
|
||||||
</Button>
|
</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) => (
|
{entries.map((entry, idx) => (
|
||||||
<StreamEntry
|
<StreamEntry
|
||||||
key={`entry-list-${idx}`}
|
key={`entry-list-${idx}`}
|
||||||
|
@ -573,27 +573,11 @@ const EntriesNavigation = () => {
|
||||||
<Center>
|
<Center>
|
||||||
<Button
|
<Button
|
||||||
onClick={() => {
|
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({
|
updateStreamBoundaryWith({
|
||||||
start_time: streamBoundary.previous_event_time,
|
start_time: streamBoundary.previous_event_time - 5 * 60,
|
||||||
end_time: streamBoundary.start_time,
|
|
||||||
include_start: false,
|
include_start: false,
|
||||||
include_end: true,
|
include_end: true,
|
||||||
|
update: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
//fetchPreviousPage();
|
//fetchPreviousPage();
|
||||||
|
|
|
@ -32,15 +32,15 @@ const useJournalEntries = ({
|
||||||
|
|
||||||
return {
|
return {
|
||||||
data: [...newEventsList],
|
data: [...newEventsList],
|
||||||
boundaries: { ...response.data.boundaries },
|
boundaries: { ...response.data.boundaries, update: false },
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const { data, isLoading, refetch } = useQuery(
|
const { data, isLoading, refetch } = useQuery(
|
||||||
["stream", { searchQuery }],
|
["stream", searchQuery],
|
||||||
getStream(searchQuery, start_time, end_time, include_start, include_end),
|
getStream(searchQuery, start_time, end_time, include_start, include_end),
|
||||||
{
|
{
|
||||||
refetchInterval: refreshRate,
|
//refetchInterval: refreshRate,
|
||||||
...queryCacheProps,
|
...queryCacheProps,
|
||||||
onSuccess: (response) => {
|
onSuccess: (response) => {
|
||||||
// response is object which return condition in getStream
|
// response is object which return condition in getStream
|
||||||
|
|
Ładowanie…
Reference in New Issue