Improve log streaming performance by using Coroutines instead of platform threads

Refactor log streaming to use a replay which eliminates the need to read the log file each time for a new subscriber and instead caches the elements directly in the sink
Fix bug in log tailing (was running with two threads instead of one)
This commit is contained in:
grimsi
2024-09-21 14:37:59 +02:00
parent 75feb614e6
commit 9219b6747a
6 changed files with 91 additions and 41 deletions
@@ -8,19 +8,17 @@ import {Button, Code, Divider, Tooltip} from "@nextui-org/react";
import {ArrowUDownLeft, SortAscending} from "@phosphor-icons/react";
function LogManagementLayout({getConfig, formik}: any) {
const [logEntries, setLogEntries] = useState<string[]>([]);
const [autoScroll, setAutoScroll] = useState(true);
const [softWrap, setSoftWrap] = useState(false);
const subscribed = useRef(false);
const logEndRef = useRef<null | HTMLDivElement>(null);
useEffect(() => {
if (subscribed.current) return;
LogEndpoint.getApplicationLogs().onNext((newEntry: string | undefined) =>
const sub = LogEndpoint.getApplicationLogs().onNext((newEntry: string | undefined) =>
setLogEntries((currentEntries) => [...currentEntries, newEntry as string])
);
subscribed.current = true;
return () => sub.cancel();
}, []);
useEffect(() => {
@@ -29,4 +29,5 @@ const menuItems: MenuItem[] = [
}
]
export const AdministrationView = withSideMenu(menuItems);
export const AdministrationView = withSideMenu(menuItems);
export default AdministrationView;
+2 -1
View File
@@ -19,4 +19,5 @@ const menuItems = [
}
]
export const ProfileView = withSideMenu(menuItems);
export const ProfileView = withSideMenu(menuItems);
export default ProfileView;