Skip to content

Commit 0a098cf

Browse files
authored
idle cpu fix test (Stirling-Tools#6015)
1 parent cfa8d1e commit 0a098cf

3 files changed

Lines changed: 28 additions & 7 deletions

File tree

app/common/src/main/java/stirling/software/common/util/FileMonitor.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ public void trackFiles() {
112112
All files observed changes in the last iteration will be considered as staging files.
113113
If those files are not modified in current iteration, they will be considered as ready for processing.
114114
*/
115-
stagingFiles = new HashSet<>(newlyDiscoveredFiles);
116-
readyForProcessingFiles.clear();
117115

118116
if (path2KeyMapping.isEmpty()) {
119117
log.warn("Not monitoring any directories; attempting to re-register root paths.");
@@ -129,8 +127,17 @@ public void trackFiles() {
129127
}
130128
}
131129

132-
WatchKey key;
133-
while ((key = watchService.poll()) != null) {
130+
// Skip expensive collection work when there is nothing to track
131+
WatchKey firstKey = watchService.poll();
132+
if (firstKey == null && newlyDiscoveredFiles.isEmpty() && readyForProcessingFiles.isEmpty()) {
133+
return;
134+
}
135+
136+
stagingFiles = new HashSet<>(newlyDiscoveredFiles);
137+
readyForProcessingFiles.clear();
138+
139+
WatchKey key = firstKey;
140+
while (key != null) {
134141
final Path watchingDir = (Path) key.watchable();
135142
key.pollEvents()
136143
.forEach(
@@ -167,6 +174,7 @@ public void trackFiles() {
167174
if (!isKeyValid) { // key is invalid when the directory itself is no longer exists
168175
path2KeyMapping.remove((Path) key.watchable());
169176
}
177+
key = watchService.poll();
170178
}
171179
readyForProcessingFiles.addAll(stagingFiles);
172180
}

frontend/src/core/components/viewer/LocalEmbedPDF.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { PluginRegistry } from '@embedpdf/core';
44
import { EmbedPDF } from '@embedpdf/core/react';
55
import { usePdfiumEngine } from '@embedpdf/engines/react';
66
import { PrivateContent } from '@app/components/shared/PrivateContent';
7+
import { useAppConfig } from '@app/contexts/AppConfigContext';
78

89
// Import the essential plugins
910
import { Viewport, ViewportPluginPackage } from '@embedpdf/plugin-viewport/react';
@@ -94,15 +95,17 @@ interface LocalEmbedPDFProps {
9495

9596
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) {
9697
const { t } = useTranslation();
98+
const { config } = useAppConfig();
9799
const [pdfUrl, setPdfUrl] = useState<string | null>(null);
98100
const [, setAnnotations] = useState<Array<{id: string, pageIndex: number, rect: Rect}>>([]);
99101
const [commentAuthorName, setCommentAuthorName] = useState<string>('Guest');
100102

101103
useEffect(() => {
104+
if (!config?.enableLogin) return;
102105
accountService.getAccountData().then((data) => {
103106
if (data?.username) setCommentAuthorName(data.username);
104107
}).catch(() => {/* not logged in or security disabled */});
105-
}, []);
108+
}, [config?.enableLogin]);
106109

107110
// Convert File to URL if needed
108111
useEffect(() => {

scripts/init-without-ocr.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,20 @@ start_unoserver_watchdog() {
287287

288288
if [ "$needs_restart" = true ]; then
289289
log "Restarting unoserver on 127.0.0.1:${port} (uno-port ${uno_port})"
290-
# Kill the old process if it exists
290+
# Kill the old process and its children (soffice) if it exists.
291+
# Capture child PIDs first, then send TERM to children before parent
292+
# so the PPID relationship is still visible. After sleep, use the
293+
# saved PIDs for SIGKILL since the parent may have already exited
294+
# and children would be reparented to init.
291295
if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null; then
296+
local child_pids
297+
child_pids=$(pgrep -P "$pid" 2>/dev/null || true)
298+
pkill -TERM -P "$pid" 2>/dev/null || true
292299
kill -TERM "$pid" 2>/dev/null || true
293-
sleep 1
300+
sleep 3
301+
if [ -n "$child_pids" ]; then
302+
kill -KILL $child_pids 2>/dev/null || true
303+
fi
294304
kill -KILL "$pid" 2>/dev/null || true
295305
fi
296306
start_unoserver_instance "$port" "$uno_port"

0 commit comments

Comments
 (0)