mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-16 19:33:11 +02:00
idle cpu fix test (#6015)
This commit is contained in:
@@ -112,8 +112,6 @@ public class FileMonitor {
|
|||||||
All files observed changes in the last iteration will be considered as staging files.
|
All files observed changes in the last iteration will be considered as staging files.
|
||||||
If those files are not modified in current iteration, they will be considered as ready for processing.
|
If those files are not modified in current iteration, they will be considered as ready for processing.
|
||||||
*/
|
*/
|
||||||
stagingFiles = new HashSet<>(newlyDiscoveredFiles);
|
|
||||||
readyForProcessingFiles.clear();
|
|
||||||
|
|
||||||
if (path2KeyMapping.isEmpty()) {
|
if (path2KeyMapping.isEmpty()) {
|
||||||
log.warn("Not monitoring any directories; attempting to re-register root paths.");
|
log.warn("Not monitoring any directories; attempting to re-register root paths.");
|
||||||
@@ -129,8 +127,17 @@ public class FileMonitor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WatchKey key;
|
// Skip expensive collection work when there is nothing to track
|
||||||
while ((key = watchService.poll()) != null) {
|
WatchKey firstKey = watchService.poll();
|
||||||
|
if (firstKey == null && newlyDiscoveredFiles.isEmpty() && readyForProcessingFiles.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
stagingFiles = new HashSet<>(newlyDiscoveredFiles);
|
||||||
|
readyForProcessingFiles.clear();
|
||||||
|
|
||||||
|
WatchKey key = firstKey;
|
||||||
|
while (key != null) {
|
||||||
final Path watchingDir = (Path) key.watchable();
|
final Path watchingDir = (Path) key.watchable();
|
||||||
key.pollEvents()
|
key.pollEvents()
|
||||||
.forEach(
|
.forEach(
|
||||||
@@ -167,6 +174,7 @@ public class FileMonitor {
|
|||||||
if (!isKeyValid) { // key is invalid when the directory itself is no longer exists
|
if (!isKeyValid) { // key is invalid when the directory itself is no longer exists
|
||||||
path2KeyMapping.remove((Path) key.watchable());
|
path2KeyMapping.remove((Path) key.watchable());
|
||||||
}
|
}
|
||||||
|
key = watchService.poll();
|
||||||
}
|
}
|
||||||
readyForProcessingFiles.addAll(stagingFiles);
|
readyForProcessingFiles.addAll(stagingFiles);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import type { PluginRegistry } from '@embedpdf/core';
|
|||||||
import { EmbedPDF } from '@embedpdf/core/react';
|
import { EmbedPDF } from '@embedpdf/core/react';
|
||||||
import { usePdfiumEngine } from '@embedpdf/engines/react';
|
import { usePdfiumEngine } from '@embedpdf/engines/react';
|
||||||
import { PrivateContent } from '@app/components/shared/PrivateContent';
|
import { PrivateContent } from '@app/components/shared/PrivateContent';
|
||||||
|
import { useAppConfig } from '@app/contexts/AppConfigContext';
|
||||||
|
|
||||||
// Import the essential plugins
|
// Import the essential plugins
|
||||||
import { Viewport, ViewportPluginPackage } from '@embedpdf/plugin-viewport/react';
|
import { Viewport, ViewportPluginPackage } from '@embedpdf/plugin-viewport/react';
|
||||||
@@ -94,15 +95,17 @@ interface LocalEmbedPDFProps {
|
|||||||
|
|
||||||
export function LocalEmbedPDF({ file, url, fileName, enableAnnotations = false, enableRedaction = false, enableFormFill = false, isManualRedactionMode = false, showBakedAnnotations = true, onSignatureAdded, signatureApiRef, annotationApiRef, historyApiRef, redactionTrackerRef, fileId, isCommentsSidebarVisible = false, commentsSidebarRightOffset = '0rem', isSignMode = false, pdfRenderMode = 'normal' }: LocalEmbedPDFProps) {
|
export function LocalEmbedPDF({ file, url, fileName, enableAnnotations = false, enableRedaction = false, enableFormFill = false, isManualRedactionMode = false, showBakedAnnotations = true, onSignatureAdded, signatureApiRef, annotationApiRef, historyApiRef, redactionTrackerRef, fileId, isCommentsSidebarVisible = false, commentsSidebarRightOffset = '0rem', isSignMode = false, pdfRenderMode = 'normal' }: LocalEmbedPDFProps) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const { config } = useAppConfig();
|
||||||
const [pdfUrl, setPdfUrl] = useState<string | null>(null);
|
const [pdfUrl, setPdfUrl] = useState<string | null>(null);
|
||||||
const [, setAnnotations] = useState<Array<{id: string, pageIndex: number, rect: Rect}>>([]);
|
const [, setAnnotations] = useState<Array<{id: string, pageIndex: number, rect: Rect}>>([]);
|
||||||
const [commentAuthorName, setCommentAuthorName] = useState<string>('Guest');
|
const [commentAuthorName, setCommentAuthorName] = useState<string>('Guest');
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (!config?.enableLogin) return;
|
||||||
accountService.getAccountData().then((data) => {
|
accountService.getAccountData().then((data) => {
|
||||||
if (data?.username) setCommentAuthorName(data.username);
|
if (data?.username) setCommentAuthorName(data.username);
|
||||||
}).catch(() => {/* not logged in or security disabled */});
|
}).catch(() => {/* not logged in or security disabled */});
|
||||||
}, []);
|
}, [config?.enableLogin]);
|
||||||
|
|
||||||
// Convert File to URL if needed
|
// Convert File to URL if needed
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -287,10 +287,20 @@ start_unoserver_watchdog() {
|
|||||||
|
|
||||||
if [ "$needs_restart" = true ]; then
|
if [ "$needs_restart" = true ]; then
|
||||||
log "Restarting unoserver on 127.0.0.1:${port} (uno-port ${uno_port})"
|
log "Restarting unoserver on 127.0.0.1:${port} (uno-port ${uno_port})"
|
||||||
# Kill the old process if it exists
|
# Kill the old process and its children (soffice) if it exists.
|
||||||
|
# Capture child PIDs first, then send TERM to children before parent
|
||||||
|
# so the PPID relationship is still visible. After sleep, use the
|
||||||
|
# saved PIDs for SIGKILL since the parent may have already exited
|
||||||
|
# and children would be reparented to init.
|
||||||
if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null; then
|
if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null; then
|
||||||
|
local child_pids
|
||||||
|
child_pids=$(pgrep -P "$pid" 2>/dev/null || true)
|
||||||
|
pkill -TERM -P "$pid" 2>/dev/null || true
|
||||||
kill -TERM "$pid" 2>/dev/null || true
|
kill -TERM "$pid" 2>/dev/null || true
|
||||||
sleep 1
|
sleep 3
|
||||||
|
if [ -n "$child_pids" ]; then
|
||||||
|
kill -KILL $child_pids 2>/dev/null || true
|
||||||
|
fi
|
||||||
kill -KILL "$pid" 2>/dev/null || true
|
kill -KILL "$pid" 2>/dev/null || true
|
||||||
fi
|
fi
|
||||||
start_unoserver_instance "$port" "$uno_port"
|
start_unoserver_instance "$port" "$uno_port"
|
||||||
|
|||||||
Reference in New Issue
Block a user