Bug 444531 - extensionCommands.js needlessly validates every command for a directories visible in the navigator
Summary: extensionCommands.js needlessly validates every command for a directories vis...
Status: RESOLVED FIXED
Alias: None
Product: Orion (Archived)
Classification: ECD
Component: Client (show other bugs)
Version: 6.0   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 7.0   Edit
Assignee: Curtis Windatt CLA
QA Contact:
URL:
Whiteboard:
Keywords: performance
Depends on:
Blocks:
 
Reported: 2014-09-18 15:56 EDT by Curtis Windatt CLA
Modified: 2014-09-25 15:37 EDT (History)
1 user (show)

See Also:


Attachments
Fix (895 bytes, patch)
2014-09-18 16:23 EDT, Curtis Windatt CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Curtis Windatt CLA 2014-09-18 15:56:02 EDT
extensionCommands.js
validateSingleItem()

This function is called for multiple times for each item in the navigator.
When the item is a directory, we check it for content types (which loops over every available content type for each period in the filename)
When no content types are returned, we assign application/octet stream as a content type (incorrect)
We then see if the command applies to the application/octet stream content type

Do the extension commands ever apply to a directory?
If yes, we should be smarter about directory content types. If no, we can skip all the work and always return false for directories.

Should a content type ever apply to a directory?
If yes, it can only be a filename match and we should have a different content type comparison.  If not, we should skip the included/excluded content types check.
Comment 1 Curtis Windatt CLA 2014-09-18 16:08:20 EDT
(In reply to Curtis Windatt from comment #0)
> Do the extension commands ever apply to a directory?

Yes, according to the wiki page, commands have optional use of the content type.
https://wiki.eclipse.org/Orion/Documentation/Developer_Guide/Plugging_into_Orion_pages#Validation_Properties

> Should a content type ever apply to a directory?

Only a file should have a content type and the wiki page seems to agree with this.

Mark, any thoughts?
Comment 2 Curtis Windatt CLA 2014-09-18 16:23:50 EDT
Created attachment 247212 [details]
Fix

My proposed fix adds two checks to short circuit the command validation.

1) If the command doesn't require or exclude any content types, don't bother looking up the content type, just return true
- This would return true before, but would do an unecessary content type lookup

2) If the item is a directory, return false
- The command includes/excludes a content type, but a directory can't have a content type, so the command isn't valid
- Previously a content type would be looked up, or application/octet-stream assigned.  So this change will affect the behaviour of a command using a content-type that matches.  I think this is reasonable as having application commands be available on directories is incorrect.
Comment 3 Mark Macdonald CLA 2014-09-18 17:09:54 EDT
(In reply to Curtis Windatt from comment #1)
> Yes, according to the wiki page, commands have optional use of the content
> type.

Yep.

> > Should a content type ever apply to a directory?
> 
> Only a file should have a content type and the wiki page seems to agree with
> this.

Also correct.
Comment 4 Curtis Windatt CLA 2014-09-25 15:37:31 EDT
http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=cc4396138cecd50f731b87940f06cbd333a6dc73
Applied the fix to master

I've had no issues with content types after running with this change for a few days. However, Orion bundle contributors could be exercising this code in different ways.