Skip to content

Commit

Permalink
feat: added opts.git.cooldown to allow updating plugins on slow con…
Browse files Browse the repository at this point in the history
…nections. Fixes #1656
  • Loading branch information
folke committed Jul 23, 2024
1 parent 839f9e7 commit d5686ef
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lua/lazy/core/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ M.defaults = {
rate = 2,
duration = 5 * 1000, -- in ms
},
-- Time in seconds to wait before running fetch again for a plugin.
-- Repeated update/check operations will not run again until this
-- cooldown period has passed.
cooldown = 0,
},
pkg = {
enabled = true,
Expand Down
16 changes: 15 additions & 1 deletion lua/lazy/manage/task/git.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ function throttle.wait()
end
end

---@param plugin LazyPlugin
local function cooldown(plugin)
if not plugin._.last_check then
return false
end
local delta = (vim.uv.now() - plugin._.last_check) / 1000
return delta < Config.options.git.cooldown
end

---@type table<string, LazyTaskDef>
local M = {}

Expand Down Expand Up @@ -266,7 +275,7 @@ M.status = {
-- fetches all needed origin branches
M.fetch = {
skip = function(plugin)
return not plugin._.installed or plugin._.is_local
return not plugin._.installed or plugin._.is_local or cooldown(plugin)
end,

---@async
Expand All @@ -287,6 +296,11 @@ M.fetch = {
self:spawn("git", {
args = args,
cwd = self.plugin.dir,
on_exit = function(ok)
if ok then
self.plugin._.last_check = vim.uv.now()
end
end,
})
end,
}
Expand Down
1 change: 1 addition & 0 deletions lua/lazy/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
---@field tasks? LazyTask[]
---@field updated? {from:string, to:string}
---@field updates? {from:GitInfo, to:GitInfo}
---@field last_check? number
---@field working? boolean
---@field pkg? LazyPkg

Expand Down

0 comments on commit d5686ef

Please sign in to comment.