From 79a80f0588374d029cc3ec881d1720e56c18e29e Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Tue, 26 Aug 2025 10:47:38 +0200 Subject: [PATCH] Add more debugs --- src/pages/Index.tsx | 49 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/src/pages/Index.tsx b/src/pages/Index.tsx index 2925804..33ce0f7 100644 --- a/src/pages/Index.tsx +++ b/src/pages/Index.tsx @@ -12,6 +12,9 @@ import { Window } from '@tauri-apps/api/window'; import { Switch } from '@/components/ui/switch'; import { useTheme } from 'next-themes'; +// Global timer that starts immediately when script loads +const GLOBAL_START_TIME = Date.now(); + // Debug timing utility const debugTiming = (operation: string, startTime: number) => { const duration = Date.now() - startTime; @@ -60,6 +63,9 @@ const mapHitToNote = (hit: any): Note => ({ }); const Index = () => { + // Log component mount time immediately + console.log(`Component mounted after ${Date.now() - GLOBAL_START_TIME}ms`); + const [currentNote, setCurrentNote] = useState(''); const [previousNote, setPreviousNote] = useState(null); const [scratchPad, setScratchPad] = useState(''); @@ -89,7 +95,7 @@ const Index = () => { const addDebugInfo = (message: string) => { const timestamp = new Date().toLocaleTimeString(); const debugMessage = `[${timestamp}] ${message}`; - setDebugInfo(prev => [...prev.slice(-19), debugMessage]); // Keep last 20 messages + setDebugInfo(prev => [...prev.slice(-499), debugMessage]); // Keep last 50 messages }; // Enhanced fetch with timing @@ -1053,7 +1059,12 @@ const Index = () => { addDebugInfo('Starting initialization...'); // Initialize notes index - if (!(await indexExists(NOTE_INDEX))) { + const notesIndexStart = Date.now(); + addDebugInfo('Checking notes index existence...'); + const notesExists = await indexExists(NOTE_INDEX); + addDebugInfo(`Notes index check completed: ${Date.now() - notesIndexStart}ms`); + + if (!notesExists) { const indexStart = Date.now(); addDebugInfo('Creating notes index...'); await fetchWithTiming(`${MEILISEARCH_ENDPOINT}/indexes`, { @@ -1110,8 +1121,18 @@ const Index = () => { }, 'Configure Notes Filterable Attributes'); addDebugInfo(`Filterable attributes configured: ${Date.now() - filterableStart}ms`); + // Gap timing + const gap1Start = Date.now(); + addDebugInfo('Starting scratch index setup...'); + // Initialize scratch index - if (!(await indexExists(SCRATCH_INDEX))) { + const scratchIndexStart = Date.now(); + addDebugInfo('Checking scratch index existence...'); + const scratchExists = await indexExists(SCRATCH_INDEX); + addDebugInfo(`Scratch index check completed: ${Date.now() - scratchIndexStart}ms`); + addDebugInfo(`Gap before scratch setup: ${Date.now() - gap1Start}ms`); + + if (!scratchExists) { const scratchStart = Date.now(); addDebugInfo('Creating scratch index...'); await fetchWithTiming(`${MEILISEARCH_ENDPOINT}/indexes`, { @@ -1155,8 +1176,18 @@ const Index = () => { }, 'Configure Scratch Filterable Attributes'); addDebugInfo(`Scratch filterable attributes configured: ${Date.now() - scratchFilterableStart}ms`); + // Gap timing + const gap2Start = Date.now(); + addDebugInfo('Starting settings index setup...'); + // Initialize settings index - if (!(await indexExists(SETTINGS_INDEX))) { + const settingsIndexStart = Date.now(); + addDebugInfo('Checking settings index existence...'); + const settingsExists = await indexExists(SETTINGS_INDEX); + addDebugInfo(`Settings index check completed: ${Date.now() - settingsIndexStart}ms`); + addDebugInfo(`Gap before settings setup: ${Date.now() - gap2Start}ms`); + + if (!settingsExists) { const settingsStart = Date.now(); addDebugInfo('Creating settings index...'); await fetchWithTiming(`${MEILISEARCH_ENDPOINT}/indexes`, { @@ -1190,9 +1221,16 @@ const Index = () => { setIsInitialized(true); const totalTime = Date.now() - initStartTime; + const totalFromStart = Date.now() - GLOBAL_START_TIME; debugTiming('Total Initialization', initStartTime); addDebugInfo(`Total Initialization: ${totalTime}ms`); - console.log('Initialization complete'); + addDebugInfo('=== INITIALIZATION SUMMARY ==='); + addDebugInfo(`Initialization time: ${totalTime}ms`); + addDebugInfo(`Total time from script load: ${totalFromStart}ms`); + addDebugInfo(`Time before initialization started: ${totalFromStart - totalTime}ms`); + addDebugInfo('If this time is much larger than the sum of individual operations,'); + addDebugInfo('there are gaps or missing operations not being logged.'); + console.log(`Initialization complete. Total time from script load: ${totalFromStart}ms`); toast({ title: "Initialization complete", description: "All indexes have been configured successfully.", @@ -1223,6 +1261,7 @@ const Index = () => { useEffect(() => { const initIndexes = async () => { + console.log(`Starting initialization after ${Date.now() - GLOBAL_START_TIME}ms`); await initializeIndexes(); }; initIndexes();