Skip to content

Commit

Permalink
Optimize repos scanning
Browse files Browse the repository at this point in the history
This is an improvement for gh-3, which was not optimal.

The query_version depends on function arg only and can be obtained at
the very begining of the function
  • Loading branch information
rosik committed Oct 30, 2018
1 parent b7bf2da commit 2f49670
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/luarocks/search.lua
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,13 @@ end
-- tables with fields "arch" and "repo".
function search.search_repos(query, lua_version)
assert(type(query) == "table")
local query_version = nil
for _, constraint in pairs(query.constraints) do
if constraint.op == '==' then
query_version = constraint.version.string
break
end
end

local results = {}
for _, repo in ipairs(cfg.rocks_servers) do
Expand All @@ -229,14 +236,8 @@ function search.search_repos(query, lua_version)
end

-- stop searching repos if exact match was found
local query_version = nil
for _, constraint in pairs(query.constraints) do
if constraint.op == '==' then
query_version = constraint.version.string
break
end
end
if results[query.name] and results[query.name][query_version] ~= nil then
local result = results[query.name]
if result and result[query_version] then
break
end
end
Expand Down

0 comments on commit 2f49670

Please sign in to comment.