-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
markup: microoptimise for many short filenames in directory #1534
Conversation
LGTM |
} | ||
|
||
name = strings.ToLower(name) | ||
if len(name) == 6 { | ||
return name == "readme" | ||
} | ||
return name[:7] == "readme." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't this be simplify by just return name == "readme" || name[:7] == "readme."
and remove if len(name) == 6 bracket ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or just return/check name[:6] == "readme" this would also validate file like README_LANGUAGE.md ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mappu Try rebasing to latest master to pass Drone build |
modules/markup/markup.go
Outdated
return name[:7] == "readme." | ||
|
||
name = strings.ToLower(name) | ||
return (name == "readme" || name[:7] == "readme.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just return name == "readme" || name[:7] == "readme."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or just
func IsReadmeFile(name string) bool {
return len(name) > 6 && strings.ToLower(name)[:6] == "readme"
}
I never really understood why we check readme.
specifically...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That what I said in my second comment, this would also validate file like README_LANGUAGE.md but maybe there is a reason ^^. I don't know in which case it is call exactly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only support the file name format like readme
or readme.md
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@appleboy we don't really have an explicit list of files we support. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I think we could also support README_LANGUAGE if README is not exist.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But that's another PR's thing, this PR is a refactor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return name == "readme" || (len(name) > 6 && name[:7] == "readme.") |
@lunny the goal of this PR is to do |
@sapk but |
@lunny I think, i didn't explain myself well enough. What, I wanted to say is :
That way we only do
Your suggestion is good functionally but keep the same operation in a more simple way but not the micro-optimization that come with this re-ordering. @mappu any news ? |
@sapk I agree with you the three steps. I mean the last step should be |
@lunny good catch |
which was why I recommended this
|
@bkcsoft but |
@lunny sorry, that's |
agree with @lunny solution. |
bf395d5
to
5e8f12c
Compare
5e8f12c
to
ac81c8f
Compare
Move strings.ToLower() after the early-return length check. This is a safe operation in all cases and should slightly improve directory listing performance when a directory contains many thousands of files with short filenames.
ac81c8f
to
aa36c4c
Compare
Thanks for the code review. I restructured the patch to only make a smaller, more-targeted change to the original function, and added test case for |
I would consider it still a improvement even if we should talk more (in other PR) about what this func should match this is not the goal of this PR. |
) (#2241) * Cleaning up public/ and documenting js/css libs. This commit mostly addresses #1484 by moving vendor'ed plugins into a vendor/ directory and documenting their upstream source and license in vendor/librejs.html. This also proves gitea is using only open source js/css libraries which helps toward reaching #1524. * Removing unused css file. The version of this file in use is located at: vendor/plugins/highlight/github.css * Cleaned up librejs.html and added javascript header A SafeJS function was added to templates/helper.go to allow keeping comments inside of javascript. A javascript comment was added in the header of templates/base/head.tmpl to mark all non-inline source as free. The librejs.html file was updated to meet the current librejs spec. I have now verified that the librejs plugin detects most of the scripts included in gitea and suspect the non-free detections are the result of a bug in the plugin. I believe this commit is enough to meet the C0.0 requirement of #1534. * Updating SafeJS function per lint suggestion * Added VERSIONS file, per request
Move strings.ToLower() after the early-return length check. This is a safe operation in all cases and should slightly improve directory listing performance when a directory contains many thousands of files with short filenames.