Add throttling to text file creation in App.tsx

This commit is contained in:
2026-01-31 01:04:56 +01:00
parent e397135c7b
commit c121bf9b7e

View File

@@ -78,6 +78,7 @@ export default function App() {
const bodyRef = useRef(body);
const historySnapshotRef = useRef<HistorySnapshot | null>(null);
const recentOpenRef = useRef(new Map<string, number>());
useEffect(() => {
@@ -288,10 +289,19 @@ export default function App() {
const handleFilePaths = useCallback(
async (paths: string[]) => {
const now = Date.now();
const txtPaths = paths.filter((path) => path.toLowerCase().endsWith(".txt"));
const recent = recentOpenRef.current;
for (const path of txtPaths) {
const key = path.toLowerCase();
const last = recent.get(key);
if (last && now - last < 1000) continue;
recent.set(key, now);
await createTextFromFile(path);
}
for (const [key, timestamp] of recent.entries()) {
if (now - timestamp > 2000) recent.delete(key);
}
},
[createTextFromFile]
);