🛠️ Add detailed logging and error handling to search worker
This commit is contained in:
@@ -3,16 +3,21 @@
|
|||||||
* Offloads search operations to a background thread to avoid blocking the UI
|
* Offloads search operations to a background thread to avoid blocking the UI
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
console.log('🔧 Search worker initialized');
|
||||||
|
|
||||||
// Listen for search requests from main thread
|
// Listen for search requests from main thread
|
||||||
self.onmessage = event => {
|
self.onmessage = event => {
|
||||||
const { lines, searchTerm, id } = event.data;
|
const { lines, searchTerm, id } = event.data;
|
||||||
|
console.log('📨 Worker received message:', { linesCount: lines?.length, searchTerm, id });
|
||||||
|
|
||||||
if (!searchTerm || !lines) {
|
if (!searchTerm || !lines) {
|
||||||
|
console.warn('⚠️ Invalid search data received');
|
||||||
self.postMessage({ type: 'complete', id, results: [] });
|
self.postMessage({ type: 'complete', id, results: [] });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
console.log('🔍 Starting search for:', searchTerm);
|
||||||
const results = [];
|
const results = [];
|
||||||
const lowerSearchTerm = searchTerm.toLowerCase();
|
const lowerSearchTerm = searchTerm.toLowerCase();
|
||||||
const chunkSize = 1000; // Process in chunks and send updates
|
const chunkSize = 1000; // Process in chunks and send updates
|
||||||
@@ -25,16 +30,19 @@ self.onmessage = event => {
|
|||||||
|
|
||||||
// Send progress updates every chunk
|
// Send progress updates every chunk
|
||||||
if ((i + 1) % chunkSize === 0) {
|
if ((i + 1) % chunkSize === 0) {
|
||||||
|
const percent = ((i + 1) / lines.length) * 100;
|
||||||
|
console.log(`📊 Progress: ${Math.round(percent)}% (${results.length} matches found)`);
|
||||||
self.postMessage({
|
self.postMessage({
|
||||||
type: 'progress',
|
type: 'progress',
|
||||||
id,
|
id,
|
||||||
percent: ((i + 1) / lines.length) * 100,
|
percent,
|
||||||
foundSoFar: results.length
|
foundSoFar: results.length
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send final results
|
// Send final results
|
||||||
|
console.log(`✅ Search complete: Found ${results.length} matches`);
|
||||||
self.postMessage({
|
self.postMessage({
|
||||||
type: 'complete',
|
type: 'complete',
|
||||||
id,
|
id,
|
||||||
@@ -42,6 +50,7 @@ self.onmessage = event => {
|
|||||||
totalMatches: results.length
|
totalMatches: results.length
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error('❌ Worker error during search:', error);
|
||||||
self.postMessage({
|
self.postMessage({
|
||||||
type: 'error',
|
type: 'error',
|
||||||
id,
|
id,
|
||||||
|
|||||||
Reference in New Issue
Block a user