Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/repo.v
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,11 @@ fn find_readme_file(items []File) ?File {
}

fn find_license_file(items []File) ?File {
files := items.filter(it.name.to_lower() == 'license')
// List of common license file names
license_common_files := ['license', 'license.md', 'license.txt', 'licence', 'licence.md', 'licence.txt']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be a global const to avoid extra allocations on each request

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Global? For big instances, with loads of users, a main project page is hit every time. But for small instances (which I believe it's the main use case), it does not occur that often.

Since this check is only done in the main project page and the list being short, I would argue that it would not make any perceived impact.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would. Because the same code powers gitly.org.

It's also a good practice in general to have such arrays as global consts, since V doesn't optimize such allocations yet.


files := items.filter(license_common_files.contains(it.name.to_lower()))

if files.len == 0 {
return none
}
Expand Down
2 changes: 1 addition & 1 deletion src/repo_routes.v
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ pub fn (mut app App) tree(mut ctx Context, username string, repo_name string, br
mut license_file_path := ''

if license_file.id != 0 {
license_file_path = '/${username}/${repo_name}/blob/${branch_name}/LICENSE'
license_file_path = '/${username}/${repo_name}/blob/${branch_name}/${license_file.name}'
}

watcher_count := app.get_count_repo_watchers(repo_id)
Expand Down
Loading