Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitde2dd41

Browse files
committed
removed redundant null safety fallbacks, added cache corruption prevention, update search filter logic to regex word boundaries
1 parenta5c0ceb commitde2dd41

File tree

1 file changed

+19
-40
lines changed

1 file changed

+19
-40
lines changed

‎src/workspacesProvider.ts‎

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -375,23 +375,20 @@ export class WorkspaceProvider
375375
agentMetadataText:string;
376376
}{
377377
// Handle null/undefined workspace data safely
378-
constworkspaceName=(workspace.workspace.name||"").toLowerCase();
379-
constownerName=(workspace.workspace.owner_name||"").toLowerCase();
378+
constworkspaceName=workspace.workspace.name.toLowerCase();
379+
constownerName=workspace.workspace.owner_name.toLowerCase();
380380
consttemplateName=(
381381
workspace.workspace.template_display_name||
382-
workspace.workspace.template_name||
383-
""
382+
workspace.workspace.template_name
384383
).toLowerCase();
385384
conststatus=(
386-
workspace.workspace.latest_build?.status||""
385+
workspace.workspace.latest_build.status||""
387386
).toLowerCase();
388387

389388
// Extract agent names with null safety
390-
constagents=extractAgents(
391-
workspace.workspace.latest_build?.resources||[],
392-
);
389+
constagents=extractAgents(workspace.workspace.latest_build.resources);
393390
constagentNames=agents
394-
.map((agent)=>(agent.name||"").toLowerCase())
391+
.map((agent)=>agent.name.toLowerCase())
395392
.filter((name)=>name.length>0);
396393

397394
// Extract and cache agent metadata with error handling
@@ -402,13 +399,16 @@ export class WorkspaceProvider
402399
agentMetadataText=this.metadataCache[metadataCacheKey];
403400
}else{
404401
constmetadataStrings:string[]=[];
402+
lethasSerializationErrors=false;
403+
405404
agents.forEach((agent)=>{
406405
constwatcher=this.agentWatchers[agent.id];
407406
if(watcher?.metadata){
408407
watcher.metadata.forEach((metadata)=>{
409408
try{
410409
metadataStrings.push(JSON.stringify(metadata).toLowerCase());
411410
}catch(error){
411+
hasSerializationErrors=true;
412412
// Handle JSON serialization errors gracefully
413413
this.storage.output.warn(
414414
`Failed to serialize metadata for agent${agent.id}:${error}`,
@@ -417,8 +417,13 @@ export class WorkspaceProvider
417417
});
418418
}
419419
});
420+
420421
agentMetadataText=metadataStrings.join(" ");
421-
this.metadataCache[metadataCacheKey]=agentMetadataText;
422+
423+
// Only cache if all metadata serialized successfully
424+
if(!hasSerializationErrors){
425+
this.metadataCache[metadataCacheKey]=agentMetadataText;
426+
}
422427
}
423428

424429
return{
@@ -454,18 +459,8 @@ export class WorkspaceProvider
454459

455460
constregexPatterns:RegExp[]=[];
456461
for(constwordofsearchWords){
457-
try{
458-
// Escape special regex characters to prevent injection
459-
constescapedWord=word.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");
460-
regexPatterns.push(newRegExp(`\\b${escapedWord}\\b`,"i"));
461-
}catch(error){
462-
// Handle invalid regex patterns
463-
this.storage.output.warn(
464-
`Invalid regex pattern for search word "${word}":${error}`,
465-
);
466-
// Fall back to simple substring matching for this word
467-
continue;
468-
}
462+
// Simple word boundary search
463+
regexPatterns.push(newRegExp(`\\b${word}\\b`,"i"));
469464
}
470465

471466
// Combine all text for exact word matching
@@ -481,27 +476,11 @@ export class WorkspaceProvider
481476
// Check for exact word matches (higher priority)
482477
consthasExactWordMatch=
483478
regexPatterns.length>0&&
484-
regexPatterns.some((pattern)=>{
485-
try{
486-
returnpattern.test(allText);
487-
}catch(error){
488-
// Handle regex test errors gracefully
489-
this.storage.output.warn(
490-
`Regex test failed for pattern${pattern}:${error}`,
491-
);
492-
returnfalse;
493-
}
494-
});
479+
regexPatterns.some((pattern)=>pattern.test(allText));
495480

496481
// Check for substring matches (lower priority) - only if no exact word match
497482
consthasSubstringMatch=
498-
!hasExactWordMatch&&
499-
(fields.workspaceName.includes(searchTerm)||
500-
fields.ownerName.includes(searchTerm)||
501-
fields.templateName.includes(searchTerm)||
502-
fields.status.includes(searchTerm)||
503-
fields.agentNames.some((agentName)=>agentName.includes(searchTerm))||
504-
fields.agentMetadataText.includes(searchTerm));
483+
!hasExactWordMatch&&allText.includes(searchTerm);
505484

506485
// Return true if either exact word match or substring match
507486
returnhasExactWordMatch||hasSubstringMatch;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp